Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

Change and replace aren't arguments for addr

They are used for routes

share|improve this answer
4  
On the other hand, if I type in $ ip addr help then usage of the ip addr command is ip addr {add|change|replace} IFADDR dev STRING [ LIFETIME ] [ CONFFLAG-LIST ] –  Martin Feb 9 '13 at 1:10
    
Of course they are arguments for ip addr. –  larsks Feb 10 at 16:27

(I realize this is an old question, but Google brought me here because I was trying to figure out exactly what change and replace do and how they are different).

I believe that both replace and change are used for modifying an existing address. Consider:

ip addr add 192.168.1.10/32 dev dummy0

This gets me:

32: dummy0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default 
    link/ether 5a:ec:58:4f:d1:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.10/32 scope global dummy0
       valid_lft forever preferred_lft forever
    inet6 fe80::58ec:58ff:fe4f:d135/64 scope link 
       valid_lft forever preferred_lft forever

If I run the same command again, I get an error:

# ip addr add 192.168.111.10/32 dev dummy0 
RTNETLINK answers: File exists

If I want to modify the flags on that address, I can use either change or replace. Here, I use ip addr change to modify the preferred_lft and valid_lft settings on that address:

# ip addr change 192.168.111.10/32 dev dummy0  preferred_lft 300 valid_lft 300
# ip addr show dummy0
32: dummy0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default 
    link/ether 5a:ec:58:4f:d1:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.10/32 scope global dynamic dummy0
       valid_lft 298sec preferred_lft 298sec
    inet6 fe80::58ec:58ff:fe4f:d135/64 scope link 
       valid_lft forever preferred_lft forever

The behavior of ip addr replace is identical. In fact, if you look at the code, they result in almost identical actions:

    if (matches(*argv, "change") == 0 ||
            strcmp(*argv, "chg") == 0)
            return ipaddr_modify(RTM_NEWADDR, NLM_F_REPLACE, argc-1, argv+1);
    if (matches(*argv, "replace") == 0)
            return ipaddr_modify(RTM_NEWADDR, NLM_F_CREATE|NLM_F_REPLACE, argc-1, argv+1);

It looks like the intention here is that change will only modify an existing address, while replace will either modify an existing address or create a new one if the specified address does not exist. In practice, it seems as if both change and replace 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 by ip addr add (or the other way around, of course).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.