Configuring Static IPv6 Address Using NetPlan on Ubuntu 18.04 and Up

From Ubuntu 18.04, a switch was made to configure network using NetPlan written in YAML. In this article, we will learn how to configure networking in newer versions of Ubuntu, such as Ubuntu 18.04, 19.04, 19.10 and 20.04 using Netplan.

To configure IPv6, you would ideally need to configure the file /etc/netplan/01-netcfg.yaml which is in YAML.

Before we head out to configuring, we need to know what interface the server is using. To find out, run

ip a

Here's my IP

In this example, we have interface called ens3. This may be different to you.

We will now see how we can configure a static IPv6 using NetPlan.

A side note on this, YAML is strict on indentation so we will use 2 spaces through out the guide.

To find out the IPv6 Address assigned to you, login to CrownPanel and navigate to Manage Network tab.

You will find a IPv6 address similar to 2604:6600:158:5171::/64. If you do not find your IPv6 allocation, please open a Support Ticket.

While adding the address you would need to change the prefix of the IP from 64 to 48 (value of the netmask).

We will edit the configuration file.

vi /etc/netplan/01-netcfg.yaml

Initially, the network is configured to DHCP.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes

Make the following changes to it now.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
      dhcp6: no
      addresses:        
        - 2604:6600:158:5171::1/48      
      gateway6: 2604:6600:158::1
      nameservers:
        addresses:
          - 2001:4860:4860::8888
          - 2001:4860:4860::8844

For nameservers, we are using google's public DNS.

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

Once you exit from the configuration. Apply the changes by running the following command,

netplan apply

Let's see if we can now Ping google's IPv6,

root@vps:~# ping6 ipv6.google.com
PING ipv6.google.com(lax17s05-in-x0e.1e100.net (2607:f8b0:4007:808::200e)) 56 data bytes
64 bytes from lax17s05-in-x0e.1e100.net (2607:f8b0:4007:808::200e): icmp_seq=1 ttl=57 time=1.24 ms
64 bytes from lax17s05-in-x0e.1e100.net (2607:f8b0:4007:808::200e): icmp_seq=2 ttl=57 time=0.720 ms
64 bytes from lax17s05-in-x0e.1e100.net (2607:f8b0:4007:808::200e): icmp_seq=3 ttl=57 time=0.849 ms

And since we have a possibility of adding large number of IPv6 from a /48 range. We will show an example of how to add a series of IPv6 into the configuration.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
      dhcp6: no
      addresses:        
        - 2604:6600:158:5171::1/48
        - 2604:6600:158:5171::2/48
        - 2604:6600:158:5171::3/48
      gateway6: 2604:6600:158::1
      nameservers:
        addresses:
          - 2001:4860:4860::8888
          - 2001:4860:4860::8844

And so on it goes.

Once you exit from the configuration file, be sure to run the netplan apply.

netplan apply

You have now static configured IPv6 Addresses on your server.

If you can not configure and facing technical difficulties, kindly reach out to us via Support Ticket.