How to set the order of ipv6


an output on my server shows IPv6 in the following order:

  inet6 addr: 2xxx:xxx:aaac:3e::10/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::1/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::2/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::3/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::4/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::5/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::6/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::7/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::8/48 Scope:Global
  inet6 addr: 2xxx:xxx:aaac:3e::9/48 Scope:Global

but in my /etc/sysconfig/network-scripts/ifcfg-eth0 they are ordered other way:

IPV6ADDR_SECONDARIES=" 2xxx:xxx:aaac:3e::2/48 \
    2xxx:xxx:aaac:3e::3/48 \
    2xxx:xxx:aaac:3e::4/48 \
    2xxx:xxx:aaac:3e::5/48 \
    2xxx:xxx:aaac:3e::6/48 \
    2xxx:xxx:aaac:3e::7/48 \
    2xxx:xxx:aaac:3e::8/48 \
    2xxx:xxx:aaac:3e::9/48 \

Note 2xxx:xxx:aaac:3e::10 comes the first, but I expect it to be the latest. Is there any way to make IPv6s to respect the order?

Best Answer

The order in which the addresses are down isn't really relevant. The problem is that Linux usually uses the first configured address as default source address for IPv4 but the last configured address for IPv6. That that address shows up on top is coincidence.

If you want to manually define the default source address you can do so in the routing table. This works for both IPv4 and IPv6:

ip add route default via 2001:db8::1 dev eth0 src 2001:db8::1234 metric 1

The metric makes sure that this route gets picked over any other default routes (SLAAC, boot scripts etc). One thing to keep in mind is that if you add such a line to your boot script is that Linux will refuse to add the route as long as the chosen source address is still in the tentative state. Recent boot scripts wait for duplicate address detection to complete to prevent this. If your system still has broken boot scripts that don't wait you can use a script as shown on instead.