EDU BLOG

Feb 26, 2025

Configuring IPv6 on the server

This article describes how to configure a network card and IPv6 address for Debian and Ubuntu.

First, install the network tools:

apt install net-tools -y

View network card information

Run ifconfig to find the network card, netmask, gateway, and other information. It will output something like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 132.98.174.248 netmask 255.255.255.192 broadcast 132.98.174.255
inet6 80e3::216:3cff:fead:5b52 prefixlen 64 scopeid 0x20<link>
inet6 1200:7e45:0:f6::1e4a:3705 prefixlen 48 scopeid 0x0<global>
inet6 1200:7e45:0:f6::235e:3b7e prefixlen 48 scopeid 0x0<global>
ether 00:16:3c:ad:5b:52 txqueuelen 1000 (Ethernet)
RX packets 304618 bytes 323216951 (308.2 MiB)
RX errors 0 dropped 3108 overruns 0 frame 0
TX packets 156356 bytes 322032853 (307.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 168017 bytes 311385231 (296.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 168017 bytes 311385231 (296.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Here, the network card name is ens3; after netmask is the netmask; after inet is the IPv4 address; and after inet6 are the IPv6 addresses.

View gateway information

To check the IPv4 gateway, use:

ip route show dev ens3

1
2
default via 132.98.174.193 onlink
132.98.174.192/26 proto kernel scope link src 132.98.174.248

To check the IPv6 gateway, use:

ip -6 route show dev ens3

1
2
3
1200:7e45::/48 proto kernel metric 256 pref medium
80e3::/64 proto kernel metric 256 pref medium
default via 1200:7e45:0:f6::1 metric 1024 onlink pref medium

The gateway address appears after default via.

Debian Configuration File

Once you have these IP details, you can write the network card configuration. Here’s the Debian network card configuration:

vi /etc/network/interfaces

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
auto lo
iface lo inet loopback

auto ens3
iface ens3 inet static # IPv4 configuration
address 132.98.174.248 # IPv4 address
gateway 132.98.174.193 # IPv4 gateway
netmask 255.255.255.192 # Subnet mask

iface ens3 inet6 static # IPv6 configuration
address 1200:7e45:0:f6::1e4a:3705 # IPv6 address
netmask 48 # Subnet mask
gateway 1200:7e45:0:f6::1 # IPv6 gateway

iface ens3 inet6 static
address 1200:7e45:0:f6::235e:3b7e # Additional IPv6 address
netmask 48 # Subnet mask

Alternatively, you can write the subnet mask and add an extra IPv6 address in this format:

1
2
3
4
5
6
7
8
9
10
11
12
auto lo
iface lo inet loopback

auto ens3
iface ens3 inet static
address 132.98.174.248/26 # IPv4 address and netmask
gateway 132.98.174.193

iface ens3 inet6 static
address 1200:7e45:0:f6::1e4a:3705/48 # IPv6 address and netmask
gateway 1200:7e45:0:f6::1
up ip addr add 1200:7e45:0:f6::235e:3b7e/48 dev ens3 # Add extra IPv6 address

To configure DNS for the server:

echo -e "nameserver 8.8.8.8 \nnameserver 8.8.4.4" >> /etc/resolv.conf

Once everything is configured, restart the network service, or reboot the server:

systemctl restart networking.service

Ubuntu Configuration File

The above configuration is for Debian. Below is the Ubuntu system configuration file. In Ubuntu, network configuration files are located in the netplan folder, typically named something like 10-ens3.yaml. Here’s an example:

vi /etc/netplan/10-ens3.yaml

1
2
3
4
5
6
7
8
9
10
network:
version: 2
renderer: networkd
ethernets:
ens3:
addresses: [132.98.174.248/26,'1200:7e45:0:f6::1e4a:3705/48'] # IP addresses
gateway4: 132.98.174.193 # IPv4 gateway
gateway6: 1200:7e45:0:f6::1 # IPv6 gateway
nameservers:
addresses: [8.8.8.8]

Save and reboot the system. Finally, test whether IPv6 is working by pinging Google or an IPv6 address from the server:

ping6 google.com

Multi IPv4 Configuration

Here’s an example of Debian multi-IP configuration for a single network card, just for reference. This is written from memory, so it hasn’t been tested!

vi /etc/network/interfaces

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
auto lo
iface lo inet loopback

auto ens3
iface ens3 inet static
address 132.98.174.248/26
gateway 132.98.174.193
dns-nameservers 8.8.8.8 8.8.4.4

iface ens3 inet6 static
address 1200:7e45:0:f6::1e4a:3705/48
gateway 1200:7e45:0:f6::1
up ip addr add 1200:7e45:0:f6::235e:3b7e/48 dev ens3
# Adding another IPv4 address below, note that you should not specify a gateway here
auto ens3:0
iface ens3:0 inet static
address 132.98.174.249/26

Once saved, restart the network or reboot the server.


Other

Cheap VPS Recommendations Page:

OLDER > < NEWER