13

I have been fiddling with IPv6 and address lifetimes. I found out that the valid_lft attribute will make a v6-address disappear automagically, if used correctly. To extend an address' lifetime I would

ip addr change 1:2:3:4::1/112 dev eth0 valid_lft 86000

The use of ip addr change does not appear in any man-page I have access to (Debian,Ubuntu, and online) and also not in the official documentation. I found it in an article referring to an email from 2009 to the ipv6-ops mailing-list.

From what I could determine playing around, I guess one can always use ip addr change instead of ip addr add, because if an address does not exist, ip will add one, just if ip addr add was used.

Is that correct, i.e., can anybody explain what precisely ip addr change does and how it differs from ip addr add?

1

1 Answer 1

6

When you are not sure of what something does, and the documentation doesn't say, you got to the sources, namely line 1588:

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

So, what it does? Returns the result of running the ipaddr_modify() function defined in line 1379 with the arguments RTM_NEWADDR and NLM_F_REPLACE.

From what I could determine playing around, I guess one can always use ip addr change instead of ip addr add, because if an address does not exist, ip will add one, just if ip addr add was used.

Is that correct, i.e., can anybody explain what precisely ip addr change does and how it differs from ip addr add?

No, add will create or execute the arguments given (if any is given), while change will look for the argument and replace it.

BTW, replace seems to be a compromise between add and change as it use a mixed bag of arguments.

3
  • 1
    And what is the effect of those flags? Because on the command line they don't really show. Especially as change works like add if the address to change does not exist yet. I didn't think I would have to dig through the kernel source (because that's where the flags are ultimately passed), in order to find out what one of the most popular command line tools for network management does. This isn't the 90s ... :-) But thanks anyways!
    – Bananguin
    Commented Sep 2, 2014 at 13:58
  • While this answer does point out that looking in the source code can help in case something isn't documented, it doesn't help me understand at all what the difference is between ip address add, ip address change, and ip address replace, nor when, how, and why I should use each. Commented Aug 25, 2023 at 22:43
  • See this answer instead: Server Fault: understanding "ip addr change" and "ip addr replace" commands. The Bing chat AI directed me to it, and it's very useful. Commented Aug 25, 2023 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .