Change ip address of specific interface

I have ether10 ip address 10.0.0.2/24.
Periodically I want to change it to 10.0.0.1/24
I read manual and saw that this is possible only using command:

/ip address set address=10.0.0.1/24 interface=ether10 numbers=

The problem is in numbers. I have to do

/ip address print

to get right item number. If item number will be changed, my script will change another interface ip address and I even can loose router’s control.

I’m writng script and I need to change ip address o f specific interface, the question is:
is it possible to do something like

/ip address ?change? interface=... address=...

or is there some walkaround known, not to use item number.

You need a “number” in order to identify the address to change because, generally, an interface might have more than one address. So the interface name is not a “key” to an unique address.

If you are sure that your interface is assigned a single address you can use the following command:

/ip address set [/ip address find interface=ether10] address=10.0.0.1/24

anyway, with exactly the same semantics, a more proper solution would be:

/ip address set [/ip address find address="10.0.0.2/24"] address=10.0.0.1/24

From the latter you can clearly see what I said: you are working with addresses, not interfaces.


Regards,
rock

Thanks, that’s exactly what I need!

You can write the command as follows:

ip address set [/ip address find address="192.168.140.*"] address=192.168.141.*

I only want to change the C subnet of the ipaddress.

THX

I’m also looking for a similar command to the above where for example I have a number of sites which all have the site number set within the IP address,
so scripting wise for the “average person” to literally go in and edit 3 :global variables can change the single octet on the IP address

e.g - Change X to site number
:global SiteNumber=x

site 6 gets 10.1.6.254/24 for example,
and I need a command that does something like - add address=10.1.$SiteNumber.254/24 interface=loopback network=10.1.$SiteNumber.0

A friend had suggested something like
so address-begining = “10.10.”; address-end = “.254/24”; full_address = $address-beginning . $6bit . $address-end;
But not sure whether this would work?

Any suggestions ?

Thanks