Linux – Why are IPv6 addresses flushed on link down

ipv6linuxlinux-networkingnetworking

There's a difference in behavior between IPv4 and IPv6 addresses assigned to a network interface: when the link is dropped, as with "ip link set down dev eth0", IPv4 addresses are retained, but IPv6 addresses are flushed. If the link is brought up again, IPv4 addresses can immediately be used to pass traffic, but IPv6 addresses must be assigned.

Is this a bug, or by design? If by design, where can I find this explicitly documented?

One co-worker has argued that it's a bug, to be fixed in an upcoming kernel; another has argued that it is by design, as IPv6 assumes dynamic addressing. I've found identical behavior in several different Linux distributions and different kernel versions, so I'm nearly certain that this is by design, but I want to find documentation, as in a citation from an RFC, to settle the matter.

If there's a workaround that forces the retention of manually-assigned IPv6 addresses, that'd be useful to know as well.

Best Answer

It sounds like the setting you are looking for is keep_addr_on_down which was introduced in Linux 4.6. Quoting Documentation/networking/ip-sysctl.txt:

keep_addr_on_down - INTEGER
    Keep all IPv6 addresses on an interface down event. If set static
    global addresses with no expiration time are not flushed.
      >0 : enabled
       0 : system default
      <0 : disabled

    Default: 0 (addresses are removed)

If you are using an older Linux version than 4.6 the best workaround I can suggest is to assign the address to a dummy interface which you keep up even if the physical interface is brought down:

modprobe dummy
ip -6 addr add dev dummy0 2001:db8::42/128