Configuring Static IPv6 Address Using NetPlan on Ubuntu 18.04 and Above

Note: This article applies only to Ubuntu versions 18.04, 20.04, 22.04 and newer.

From Ubuntu 18.04 onwards, Ubuntu switched over the method used to configure networking over to using NetPlan, which uses configuration files written in YAML. In this article, we will learn how to configure IPv6 networking in these newer versions of Ubuntu using netplan,

To configure IPv6, you would ideally need to configure the file /etc/netplan/00-installer-config.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 an interface called ens3. This may be different for you.

Configuring static IPv6 with Netplan Routes

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

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

You will find an IPv6 address similar to 2a0b:3c40:11:71d8::/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 to the netmask. (In this example we change prefix from 64 to 48)

To edit the configuration file.

nano /etc/netplan/00-installer-config.yaml

Initially, the network is configured to DHCP.

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

Method 1 - Configure only IPv6 as static

In the first method, we will configure the IPv6 address as static and leave IPv4 as default / via DHCP.

Make the following changes to it now,

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: true
      dhcp6: false
      addresses:
        - IPv6-Address/IPv6-Netmask
      nameservers:        
        addresses:
          - 2001:4860:4860::8888
          - 2001:4860:4860::8844
      routes:
          - to: "::/0"
            via: "Pv6-Gateway"
            on-link: true

Example,

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: true
      dhcp6: false
      addresses:
        - 2a0b:3c40:11:71d8::1/48
      nameservers:
        #search: [mydomain, otherdomain]
        addresses:
          - 2001:4860:4860::8888
          - 2001:4860:4860::8844
      routes:
          - to: "::/0"
            via: "a0b:3c40:11::1"
            on-link: true

Method 2 - Configure both IPv4 and IPv6 as static

In this method, we will configure both IPv4 and IPv6 address as static on the server.

Make the following changes,

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: false
      dhcp6: false
      addresses:
        - 185.228.83.67/24
        - 2a0b:3c40:11:71d8::1/48
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
          - 2001:4860:4860::8888
          - 2001:4860:4860::8844
      routes:
          # IPv4 route
          - to: default
            via: 185.228.83.1
          # IPv6 route
          - to: "::/0"
            via: "a0b:3c40:11::1"
            on-link: true

Under addresses,

  • We've added the Main IPv4 of the server followed by it's prefix. If your netmask is "255.255.255.0", then use /24 prefix.
  • We've added the IPv6 address followed by it's prefix. In this case, please use the value provided in "Netmask" column.

You can find more info on how to use the right prefix here.

In routes,

  • via defines the gateway IP of the IPv4 and IPv6 address. This value can be found under the "Gateway" column.

Netmask and Gateway can be found in "Manage Network" page in CrownPanel.

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

8.8.8.8
8.8.4.4
2001:4860:4860::8888
2001:4860:4860::8844

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

netplan try

Note: If everything is good it will ask to press Enter before 120 sec if you didn't confirm by hitting Enter it will timeout and revert the changes made on the config file.

Output,

root@vps:~# netplan try
Warning: Stopping systemd-networkd.service, but it can still be activated by:
  systemd-networkd.socket
Do you want to keep these settings?

Press ENTER before the timeout to accept the new configuration

Changes will revert in 118 seconds
Configuration accepted.
root@vps:~#

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

root@vps:~# ping6 -c3 ipv6.google.com
PING ipv6.google.com(ams17s08-in-x0e.1e100.net (2a00:1450:400e:80e::200e)) 56 data bytes
64 bytes from ams17s08-in-x0e.1e100.net (2a00:1450:400e:80e::200e): icmp_seq=1 ttl=60 time=2.92 ms
64 bytes from ams17s08-in-x0e.1e100.net (2a00:1450:400e:80e::200e): icmp_seq=2 ttl=60 time=1.55 ms
64 bytes from ams17s08-in-x0e.1e100.net (2a00:1450:400e:80e::200e): icmp_seq=3 ttl=60 time=1.56 ms

--- ipv6.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 1.554/2.008/2.915/0.641 ms

Configure Multiple IPv6 Addresses

After you've configured one of the IPv6 as static using the above method, we will see ho wwe can configure multiple IPv6 addresses in the same configuration file.

You usually get a /64 IPv6 subnet assigned to the server. This subnet consists a total of 18,446,744,073,709,551,616 IPv6 addresses.

You can add something as below while configuring the addresses,

      addresses:
        - 2a0b:3c40:11:71d8::1/48
        - 2a0b:3c40:11:71d8::10/48
        - 2a0b:3c40:11:71d8::20/48
        - 2a0b:3c40:11:71d8:ffff::10/48
        - 2a0b:3c40:11:71d8:ffff:ffff::ffff/48
        - 2a0b:3c40:11:71d8:ffff:ffff:ffff:ffff/48

And in complete, it looks like this,

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: false
      dhcp6: false
      addresses:
        - 185.228.83.67/24
        - 2a0b:3c40:11:71d8::1/48
        - 2a0b:3c40:11:71d8::10/48
        - 2a0b:3c40:11:71d8::20/48
        - 2a0b:3c40:11:71d8:ffff::10/48
        - 2a0b:3c40:11:71d8:ffff:ffff::ffff/48
        - 2a0b:3c40:11:71d8:ffff:ffff:ffff:ffff/48
      nameservers:
        #search: [mydomain, otherdomain]
        addresses:
          - 8.8.8.8
          - 8.8.4.4
          - 2001:4860:4860::8888
          - 2001:4860:4860::8844
      routes:
          # IPv4
          - to: default
            via: 185.228.83.1
          # IPv6
          - to: "::/0"
            via: "a0b:3c40:11::1"
            on-link: true

You have now static configured IPv6 Addresses on your server.

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