What onboot configuration option will set the default outbound IPv6 address to use when a Linux machine initiates an outbound IPv6 connection? IPV6ADDR= does not work to specify the default outbound IPv6 address.

I have a machine with several IPv6 alias addresses on eth0. I specify ifcfg-eth0 to set the IPV6ADDR_SECONDARIES= to a long list of IPv6 addresses.

Linux seems to pick one of those IPv6 addresses at random to use as its default outbound IPv6 to use. No rhyme or reason on which it uses, and it's annoying. Some IPv6 addresses are for incoming services only, and I don't want to expose those addresses to others when initiating outbound connections.

I can manually tell Linux to stop using an outbound IPv6 address:

ip -6 addr show | grep global
sudo ip addr change 2111:aaaa:bbbb:cccc:1:2:3:4 dev eth0 preferred_lft 0
ip -6 addr show | grep global

Then it stops using 2111:aaaa:bbbb:cccc:1:2:3:4 as the default outbound IPv6, and starts using the next one on its list according to ip -6 addr show | grep global. This is a manual workaround until I find some IPV6_OUTBOUND= or whatever parameter to specify the main outbound IPv6 address.

In comparison, IPv4 seems to use its IPADDR= as the default outbound IP. The IPv6 version of this parameter, IPV6ADDR= does not set the default outbound IPv6 address - it often uses one on the IPV6ADDR_SECONDARIES= list.

I am using Centos 6.


The way to do this is surprisingly in the routing table. Each route can have a src option that defines the default source address for that route. That way you can set a different default source address for example for use within your own data centre and for when using the default route.

In CentOS using the networking-scripts, you can store a custom route in /etc/sysconfig/network-scripts/route6-<interface>. Its syntax is the same as ip route add, with those three tokens omitted:

default via 2001:db8:c0:ffee:: src 2001:db8::123 dev enp4s0f0 metric 1
  • This was the only working fix for me. But there seems to be a race condition between adding the LAN IP and changing the default route to this one with src of said LAN IP, so a sleep command needs to be used in between.
    – Zdenek
    Apr 16 at 20:40

This is happening because all of your IPv6 addresses are considered equal in source address selection. When no address is preferred over another, Linux chooses one at random.

This is a bit of a hack, and slightly abuses the definition of an IPv6 home address, but it should do:

Set the desired outgoing address as the home address. This causes the designated address to win when the source selection rules are applied.

ip addr change 2001:db8:c0:ffee::4 home dev enp4s0f0

At the moment this can't be set up in the Red Hat networking scripts; you will need to add it in a local script such as /sbin/ifup-local.

And note that you probably can't do this in CentOS 6. You'll need CentOS 7.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.