Configuring IPv6 address for Ubuntu 20.04

hqs Posted on 2022-09-25 1839 Views


  • This article uses VPS from xtom as an example to show how to add an IPv6 address to the existing mechine.
  • Special thanks to cyp0633's blog for helping me to figure out how to use Netplan rather than /etc/network/interface which appeared in older version of Ubuntu to configuring IPv6.
  • The process and interface might differ for different machine, so this guide will only use for reference, please notice the difference and adjust it.

Allocate an IPv6 address

This step should be done automatically by the Service provider, including IPv6 addresses and the gateway address.

Config Netplan setting

Most of the tutorials found on the web are for older Ubuntu versions, while Ubuntu 20.04.3 already uses Netplan.

Use SSH to connect to the server. If you are worried about losing connection due to improper operation, you can connect directly using VNC as described in the next chapter.

The default configuration file for Netplan is in /etc/netplan, which should contain a YAML file, i.e. its configuration file.

Open this file with your favorite code editor (Vim, Nano, whatever) and you will see the configuration file in the following form. There are some minor differences that can be ignored.

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true

Change it to the following, the core of which will be explained below.

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      dhcp6: true
      gateway4: x.x.x.x # IPv4 gateway
      gateway6: xx::1 # IPv6 gateway
      addresses: [x.x.x.x/24, 'x:x::/Bitmask'] # IPv4 address、IPv6 adrress、IPv6 Bitmask respectively

From the page Stallion just came from, click on the IPv4 tab and then find the Settings icon under the IPv4 addresses in the Normal section below. Click on it, and then click on Network Settings.

The IP Address is your IPv4 address and the Gateway is your IPv4 gateway, replace them with the changes above. If your Netmask is also 255.255.255.0, then /24 does not need to be changed, they have the same meaning, just a conversion between Netmask and Bitmask, the former is the usual expression for IPv4, the latter is the expression for IPv6, Netplan uses the latter uniformly.

In the same way, go to the IPv6 address settings you just assigned, replace the IP Address and Gateway with the corresponding values, and replace the Bitmask value with the Netmask/Bitmask value on the webpage, which is usually 48.

Save the configuration file and use the command sudo netplan try to automatically check the configuration file and press enter if it looks OK. Then use sudo netplan apply to apply the changes.

Check the internet connection

This command will help you to find the IPv6 address and check for the connection.

curl ip.sb -6
This author has not provided a description.
Last updated on 2022-09-25