3

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:

IPV6INIT=yes
IPV6ADDR=2xxx:xxx:aaac:3e::1/48
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 \
    2xxx:xxx:aaac:3e::10/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?

Alex
  • 75
  • 6

2 Answers2

5

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 https://www.vaspects.com/2013/12/11/services-dont-bind-to-ipv6-address/ instead.

Sander Steffann
  • 7,712
  • 19
  • 29
  • Linux uses *longest common prefix* to determine source address in the absence of a source address hint in the routing table. – Simon Richter Oct 13 '14 at 13:09
  • Simon: true, but addresses in the same prefix will all have the same common prefix for all destinations that are not in the same subnet. When there are only statically configured addresses it will usually use the most recently added address. – Sander Steffann Oct 13 '14 at 17:28
  • Good point. IIRC there is also the `secondary` flag if you want an address to be excluded here. – Simon Richter Oct 13 '14 at 18:20
  • I just tried that, but when adding an address the `secondary` flag is not accepted. (also: check `ip -6 addr help`, `secondary` is in `FLAGS` not in `CONFFLAGS`) – Sander Steffann Oct 13 '14 at 19:19
  • Thank you for answers. What do I miss? When I try to add route as root I get: # ip -6 route add default via 2xxx:xxx:aaac:3e::1 dev eth0 src 2xxx:xxx:aaac:3e::11 metric 1 RTNETLINK answers: No route to host – Alex Oct 14 '14 at 08:23
  • 1
    The source address you are using (`2xxx:xxx:aaac:3e::11`) is not one of the addresses you showed in your question. And also based on the information you gave in your question you are configuring yourself (`2xxx:xxx:aaac:3e::1`) to be your own default gateway... That won't work. You need to put one of your own addresses as source address and use the real gateway address. – Sander Steffann Oct 14 '14 at 11:06
  • 1
    Maybe you mixed up your gateway address and your preferred source address? if your source address is `2xxx:xxx:aaac:3e::1` and your default gateway is `2xxx:xxx:aaac:3e::11` then the correct command is: `ip -6 route add default via 2xxx:xxx:aaac:3e::11 dev eth0 src 2xxx:xxx:aaac:3e::1 metric 1` – Sander Steffann Oct 14 '14 at 11:08
0

I don't think it is possible. You can maybe add a label (see man ip-addr) but I don't think it will change anything. By the way, what is the problem with the order ? All the IPs are in the same network, so they can be used one or one. If you describe more your problem, we can maybe help you more.

Dom
  • 6,743
  • 1
  • 20
  • 24
  • That's not a real problem at least for now, but it might trouble a little bit. The main reason I ask it is that the very first address is always used for outgoing connections. And if exim can be configured and bind to a specific IPv6 address, other services might miss such an opportunity. That's it. – Alex Oct 13 '14 at 07:17
  • 1
    You can force your servers to use the primary address or establish source routing to solve your problem – Dom Oct 13 '14 at 10:59