5

I have several IPv6 addresses on a CentOS 7 server and need to make a specific v6 address the default address used in routing. I have been able to do this by modifying the route table.

ip -6 route del default
ip -6 route add default via 2001:470:xxxx:xx::1 src 2001:470:xxxx:xx::6

Problem is each time the network interface is restarted or the server itself is rebooted, the change to the default IPv6 route is lost. How can I make this change persistent so its permanently kept?

James White
  • 674
  • 3
  • 18
  • 32
  • 1
    Just make sure that the desired address is the first one assigned to the interface. – Michael Hampton Aug 26 '15 at 17:28
  • In my case, the last address in `IPV6ADDR_SECONDARIES` configured on my `eno1` interface becomes the primary, even the primary IPv6 defined isn't set as the default. – James White Aug 26 '15 at 17:49
  • 1
    Yes, they get assigned in reverse order, which is annoying and I suspect it's a bug. – Michael Hampton Aug 26 '15 at 17:50
  • Really?! That's crazy. I've just switched the `IPV6ADDR_SECONDARIES` and put the desired v6 address as the last value and it works! Didn't realise this behaviour exists. – James White Aug 26 '15 at 17:55

2 Answers2

6

When Red Hat's networking scripts set multiple IPv6 addresses configured in /etc/sysconfig/network-scripts/ifcfg-*, for whatever reason, they are applied in reverse order, so that the last address listed in IPV6ADDR_SECONDARIES becomes the address used by default for outgoing connections. Reversing the order in which IPv6 addresses are listed is generally sufficient to fix the problem.

To answer the only vaguely related bounty question: IPv6 static routes can be set by adding them to a corresponding /etc/sysconfig/network-scripts/route6-*. The format of this file is the same as the ip route add command with that bit omitted, e.g.:

default via 2001:db8:dead:beef:: dev eno1
2001:db8:deca:fbad::/64 via 2001:db8:dead:beef::8bad:f00d dev eno1
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

One place you can put it is in the /sbin/ifup-local file which is run when an interface comes up.

#!/bin/sh
if [[ "$1" == "eth0" ]]
then
  ip -6 route del default
  ip -6 route add default via 2001:470:xxxx:xx::1 src 2001:470:xxxx:xx::6
else
  #DO_NOTHING
fi

It doesn't exist by default so you will need to create it and set permissions to make it executable.

Brian
  • 3,476
  • 18
  • 16