At the moment I have following IPv4 addresses associated with eth0 interface:
T60:~ # ip -V
ip utility, iproute2-ss110629
T60:~ # ip addr show dev eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:15:58:2a:84:3e brd ff:ff:ff:ff:ff:ff
inet 10.11.12.2/24 scope global eth0
inet 10.11.12.3/24 scope global secondary eth0
inet 10.11.12.4/24 scope global secondary eth0
inet6 fe80::215:58ff:fe2a:843e/64 scope link
valid_lft forever preferred_lft forever
T60:~ #
I would like to replace or change 10.11.12.3/24 address to 10.11.12.6/24. How to do this? If I execute ip addr change 10.11.12.6/24 dev eth0
or ip addr replace 10.11.12.6/24 dev eth0
then 10.11.12.6 is just added to eth0. In addition, in case of change/replace, shouldn't the syntax be change/replace from 10.11.12.3/24 to 10.11.12.6/24
? I know that I can use ip addr del
command, but how to achieve this with ip addr change
or ip addr replace
?
(I realize this is an old question, but Google brought me here because I was trying to figure out exactly what
change
andreplace
do and how they are different).I believe that both
replace
andchange
are used for modifying an existing address. Consider:This gets me:
If I run the same command again, I get an error:
If I want to modify the flags on that address, I can use either
change
orreplace
. Here, I useip addr change
to modify thepreferred_lft
andvalid_lft
settings on that address:The behavior of
ip addr replace
is identical. In fact, if you look at the code, they result in almost identical actions:It looks like the intention here is that
change
will only modify an existing address, whilereplace
will either modify an existing address or create a new one if the specified address does not exist. In practice, it seems as if bothchange
andreplace
will add the address if it does not already exist.If you actually want to add a new address and remove an old one, you will need to do that in two steps, using
ip addr del
followed byip addr add
(or the other way around, of course).