How to assign an IPv6 address to an interface

Stop running away from this, request and assign an IPv6 address to an external interface to make content available over both IPv4 and IPv6.

Assign an IPv6 address to an interface using ip utility.

$ ip -6 address add 2A00:0C98:2060:A000:0001:0000:1d1e:ca75/64 dev eth0

Use the same tool to configure the default route.

$ ip -6 route add default via 2A00:0C98:2060:A000:0000:0000:0000:0001 dev eth0

Ping the gateway to ensure you can reach it.

$ ping6 -c1 2A00:0C98:2060:A000:0000:0000:0000:0001
PING 2A00:0C98:2060:A000:0000:0000:0000:0001(2a00:c98:2060:a000::1) 56 data bytes
64 bytes from 2a00:c98:2060:a000::1: icmp_seq=1 ttl=64 time=0.197 ms

--- 2A00:0C98:2060:A000:0000:0000:0000:0001 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.197/0.197/0.197/0.000 ms

Ping external address to confirm that everything is working properly before you make above-mentioned changes persistent.

$ ping6 -c1 example.org
PING example.org(2606:2800:220:1:248:1893:25c8:1946) 56 data bytes
64 bytes from 2606:2800:220:1:248:1893:25c8:1946: icmp_seq=1 ttl=59 time=98.1 ms

--- example.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 98.168/98.168/98.168/0.000 ms

Edit /etc/network/interfaces configuration file, add an inet6 address to make it permanent.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
  address 84.16.240.28
  netmask 255.255.255.192
  network 84.16.240.0
  broadcast 84.16.240.63
  gateway 84.16.240.62
  # dns-* options are implemented by the resolvconf package, if installed
  dns-nameservers 37.58.58.137 91.109.25.225
  dns-search localdomain

iface eth0 inet6 static
  address 2A00:0C98:2060:A000:0001:0000:1d1e:ca75
  netmask 64
  gateway 2A00:0C98:2060:A000:0000:0000:0000:0001

Use the following example as a starting point to assign more and more IPv6 addresses.

...
iface eth0 inet6 static
  address 2A00:0C98:2060:A000:0001:0000:1d1e:ca75
  netmask 64
  gateway 2A00:0C98:2060:A000:0000:0000:0000:0001
  up   ip -6 addr add 2a00:0c98:2060:a000:0001:0000:0ca7:000a/64 dev $IFACE label $IFACE:0
  down ip -6 addr del 2a00:0c98:2060:a000:0001:0000:0ca7:000a/64 dev $IFACE label $IFACE:0
  up   ip -6 addr add 2a00:0c98:2060:a000:0001:0000:0ca7:000b/64 dev $IFACE label $IFACE:1
  down ip -6 addr del 2a00:0c98:2060:a000:0001:0000:0ca7:000b/64 dev $IFACE label $IFACE:1
...

Did you know that you can hide funny phrases inside IPv6 addresses?

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu