Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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.

share|improve this answer
    
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 Sep 2 at 13:58

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.