Today we will be going over how to add an additional IPv6 address to your VPS.
This is a two part process. The first part adds the additional IPv6 address as a sub address onto the existing interface. The second part creates a startup script to make the change persistent on reboot.
You can find the IPv6 addresses assigned to your VPS on the VPS Dashboard:
You may need to select "View All" to open the drop down to display additional addresses on your VPS dashboard.
Please note these commands are executed as the root user. You may need to be root or use sudo to execute these commands.
First we are going to add the additional IPv6 address assigned to our machine to our existing eth0 interface as a sub address.
ip -6 addr add x:x:x:x::x/124 dev eth0
Substitute the x:x:x:x::x part of the command with the additional address assigned to your VPS.
You can confirm the address was assigned to your interface using the following command:
ip a
This will display the current ip settings assigned to your network interfaces. Both the original and new address should be present.
You should now be able to ping and connect to your VPS using the additional address.
The next step is to make this additional address persistent on reboot. We will make a startup script, and then tell rc.local to execute it on boot.
We will use nano to create the startup script.
nano /usr/sbin/network.sh
Put the following lines in:
#! /bin/bash ip -6 addr add x:x:x:x::x/124 dev eth0
Remember to replace x:x:x:x::x with the additional address assigned to your machine.
Make it executable.
chmod +x /usr/sbin/network.sh
Then we will use rc.local to execute the script at boot. If rc.local is not already present, create it with the following command:
touch /etc/rc.local
Edit rc.local with nano to point at your network.sh to have it run on boot.
nano /etc/rc.local
Then put the following lines in:
#! /bin/bash /usr/sbin/network.sh || exit 1 exit 0
Next make it executable.
chmod +x /etc/rc.local
Now when your VPS reboots rc.local will execute your network.sh to apply the additional IP address to your interface automatically.
That's it. You should now have multiple IPv6 addresses assigned to your interface, and be able to connect to them.
If you have more than one additional IPv6 address, simply add another ip command to the script.
For example:
#! /bin/bash ip -6 addr add x:x:x:x::10/124 dev eth0 ip -6 addr add x:x:x:x::20/124 dev eth0
Where x:x:x:x::10 is the first address and x:x:x:x::20 is the second.