How can I use additional IPv6 addresses with Linux?

IPv6 addresses offer numerous advantages for modern networks, particularly in server administration. With multiple IPv6 addresses, you can run different services on different addresses, manage security zones better, and set up virtual hosts. This improves the organization, security, and accessibility of your services.

However, when using KVM servers with Vionity, there is a challenge: Vionity overwrites the interfaces file with each restart, causing manual changes to be lost. To ensure that additional IPv6 addresses persist after each restart, alternative methods like scripts in the if-up.d and if-down.d directories are necessary. These guarantee a stable and consistent network configuration despite Vionity’s interventions.

Step-by-step guide

If you want to add additional IPv6 addresses to your default interface (e.g., eth0) and ensure that these settings persist after a reboot, follow this guide. Here, you will learn how to create scripts for if-down.d and if-up.d to add and remove the IPv6 address 2a12:edc0:4:1337::4242/64.

Make sure you have root privileges, as you will need to make changes to the network scripts.

Add IPv6 address

Create script for if-up.d:
Create a new file in the directory /etc/network/if-up.d/. Name it, for example, add-ipv6.

sudo nano /etc/network/if-up.d/add-ipv6

Content of the script add-ipv6:

#!/bin/sh
# Add additional IPv6 address when eth0 interface comes up

if [ "$IFACE" = "eth0" ]; then
   ip -6 addr add 2a12:edc0:4:1337::4242/64 dev eth0
fi

Make the file executable:

sudo chmod +x /etc/network/if-up.d/add-ipv6

Remove IPv6 address

Create script for if-down.d:
Create a new file in the directory /etc/network/if-down.d/. Name it, for example, remove-ipv6.

sudo nano /etc/network/if-down.d/remove-ipv6

Content of the script remove-ipv6:

#!/bin/sh
# Remove additional IPv6 address when eth0 interface goes down

if [ "$IFACE" = "eth0" ]; then
   ip -6 addr del 2a12:edc0:4:1337::4242/64 dev eth0
fi

Make the file executable:

sudo chmod +x /etc/network/if-down.d/remove-ipv6

Test the configuration

After creating and executing the scripts, you can restart your network interface to test the configuration:

sudo ifdown eth0 && sudo ifup eth0

Then, check if the IPv6 address has been added correctly:

ip -6 addr show dev eth0

If everything is set up correctly, the IPv6 address 2a12:edc0:4:1337::4242/64 should be displayed.

Leave a Reply

Your email address will not be published. Required fields are marked *