Info
Content

Configuring a Static IPv6 Address in Linux


Debian Based (Debian & Ubuntu)

Use your favourite text editor to edit the network interfaces file

nano /etc/network/interfaces

An example of a IPv6 network configuration would be as follows, ensure to adjust it accordingly (device name and IP address settings)

auto eth0 #Not necessary if this has already been defined for an IPv4 address
iface eth0 inet6 static
 address 2a00:1768:2001:2a00::4
 netmask 64
 gateway 2a00:1768:2001:2a00::1
 dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844

Multiple IP addresses would have to be added via aliases. (eth0:0, eth0,1 etc.) 
Adding IPv6 DNS nameservers is only required if the server does not have any IPv4 connectivity, as AAAA-records (the IPv6 equivalent of a A-record) may also be resolved via IPv4.
Keep in mind most systems are only able to keep track of three DNS servers at the same time, regardless of IPv4/IPv6

RHEL Based (CentOS)

First of all, IPv6 networking has to be enabled in the 'network' file.
Edit this file using your favourite text editor

nano /etc/sysconfig/network

Make sure to append the following to this file

NETWORKING_IPV6=yes

Now the IPv6 networking has been enabled the IPv6 addresses can be added to the relevant network configuration file.

nano /etc/sysconfig/network-scripts/ifcfg-eth0

The following lines would have to be added to the already present file.

IPV6INIT=yes
IPV6ADDR=2a00:1768:2001:2a00::4/64
IPV6_DEFAULTGW=2a00:1768:2001:2a00::1

Multiple IPv6 addresses may be easily added by defining them as secondaries and adding them to same file.

IPV6_SECONDARIES="2a00:1768:2001:2a00::4 2a00:1768:2001:2a00::5 2a00:1768:2001:2a00::6"

IPv6 DNS servers may be added to the /etc/resolv.conf file. This is only required if the server does not have any IPv4 connectivity, as AAAA-records (the IPv6 equivalent of a A-record) may also be resolved via IPv4.

nano /etc/resolv.conf

Simply add the following lines.

nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

Netplan (Ubuntu 17.10+)

Use your favourite text editor the edit the relevant network configuration file.

nano /etc/netplan/01-netcfg.yaml

Assuming you already have a working IPv4 configuration, you may simply add two lines to the existing netplan configuration. These lines being the IPv6 address under 'addresses', and the 'gateway6' line for your IPv6 gateway.

network:
 version: 2
 renderer: networkd
 ethernets: 
   eth0:
     dhcp4: no 
     dhcp6: no 
     addresses:
- 192.168.1.2/24
- 2a00:1768:1000:22:1::5/64
     gateway4: 192.168.1.254 
gateway6: 2a00:1768:1000:22:1::1
     nameservers: 
       addresses: [77.247.176.114,77.247.176.115,85.159.238.17]

For changes to take effect, the configuration will have to be applied. Appending --debug may help you troubleshoot if you're running into any issues.

netplan apply
No Comments
Back to top