Assuming you’re setting up services to use IPv6, you may have noticed a slightly odd behaviour. When making an outbound connection, the most recently added (or last listed in the config) IPv6 is used. This can be annoying when connecting, for example, to IP restricted APIs or even for sending email.
Whilst it’s possible to add the IP you want to use last, as soon as you need to add another address this becomes messy. Thankfully, there’s an easy way to set a static route so that you can always connect via the address you want.
First, use the command ‘ip a’ to find the name of your internet facing network card. You may get a list of cards, find the one with your external IP following it. Usually this is called ‘eth0’.
Now, create a file using your editor of choice – nano for me – in the following way:
sudo nano /etc/sysconfig/network-scripts/route6-eth0
replace eth0 with the name of your adaptor if different.
In that file, just add the following line:
::/0 via aaaa:bbbb:cccc:dddd:eeee::ffff dev eth0
replacing, of course, with your choice of outgoing IP and adaptor name.
CTRL+O to save then CTRL+X to exit
Restart your network on the machine:
service network restart
And you’re ready to go.