Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Networking

Configure IPv6 on Ubuntu Server with Netplan

Set up IPv6 on Ubuntu 24.04 and 26.04 with Netplan: a static address and gateway, router advertisements, netplan try, firewall rules and when to turn it off.

CloudSat teamNovember 18, 20267 min read
Abstract illustration of a long hexadecimal address unfolding like a ribbon from a server toward a glowing globe
On this pageCheck what the server already has

An Ubuntu server either picks up IPv6 by itself from router advertisements, or it needs an address and gateway that the provider gives you. Netplan handles both. The method below checks what you already have, writes a static configuration in the right file, applies it with an automatic rollback, and opens the firewall for both address families. It covers Ubuntu 24.04 and 26.04 LTS, and 22.04 behaves the same way.

Check what the server already has

ip -6 addr show scope global
ip -6 route show default
ping -6 -c 3 2606:4700:4700::1111
What you see What it means
Only an fe80:: address Link-local only. IPv6 works on the local segment but not beyond it
A global address but no default route Half configured. Replies cannot find their way out
A global address, a default route, and ping replies Working. Skip to the firewall section
Network is unreachable from ping No IPv6 route at all

Global addresses start with 2 or 3 today. Every interface always has an fe80:: address; it is normal and is not a sign of a problem.

Get the values from your provider

You need three things: the address, its prefix length (usually /64, sometimes /128 or /48), and the gateway. The gateway is often the first address of the prefix, such as 2001:db8:10:20::1, or a link-local address such as fe80::1. On a CloudSat server, the IPv6 address is listed in the Details card of the server's Overview tab, as described in Your server IPv4 and IPv6 addresses.

If the provider delivers IPv6 through router advertisements (SLAAC), you may need nothing at all. Check ip -6 addr after a reboot before writing any configuration. A few networks hand out addresses with DHCPv6 instead; for those, dhcp6: true in the interface block replaces the static address and route shown below.

Find the right file to edit

Netplan reads every .yaml file in /etc/netplan/. On cloud images, the network setup lives in 50-cloud-init.yaml, which cloud-init generates from the provider's metadata. Its header warns that edits do not survive a reboot. To keep your changes, tell cloud-init to stop managing the network first:

echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
sudo cp /etc/netplan/50-cloud-init.yaml /root/50-cloud-init.yaml.bak

From now on, address changes made in the provider's panel no longer reach the server automatically, so keep the backup and a note of what you changed.

Write a static IPv6 configuration

Find the interface name with ip -br link (often ens3, enp1s0 or eth0) and add the IPv6 keys to its existing block. Leave the IPv4 lines as they are:

network:
  version: 2
  ethernets:
    ens3:
      dhcp4: true
      accept-ra: false
      addresses:
        - "2001:db8:10:20::2/64"
      routes:
        - to: "::/0"
          via: "2001:db8:10:20::1"
      nameservers:
        addresses: ["2606:4700:4700::1111", "1.1.1.1"]

What each key does:

  • addresses takes the address with its prefix length. Add more lines for extra addresses from the same prefix.
  • routes with to: "::/0" is the IPv6 default route. The older gateway6 key is deprecated, so use this form.
  • accept-ra: false makes the server ignore router advertisements, so it does not grow a second, automatic address or route next to your static one. If your provider relies on advertisements, remove this line and the static route.
  • nameservers can mix IPv6 and IPv4 resolvers.

If the provider's gateway is outside your prefix, for example with a /128 address, add on-link: true under the route so the kernel knows it can reach the gateway directly. A link-local gateway such as fe80::1 works without it.

Netplan also warns when configuration files are readable by other users. Fix that once:

sudo chmod 600 /etc/netplan/*.yaml

Apply it with a safety net

A typo in network configuration can cut off your SSH session. Netplan has an undo button for exactly this:

sudo netplan generate      # syntax check, no changes applied
sudo netplan try           # applies, then rolls back unless you confirm

netplan try waits 120 seconds by default. Open a second SSH session while it waits, and if that session works, press Enter in the first to keep the configuration. If you lose the connection, do nothing: the old settings come back on their own when the timer runs out. Once confirmed, the configuration stays active across reboots; later edits go through the same generate and try steps.

Test from inside and outside

ip -6 addr show dev ens3
ip -6 route
ping -6 -c 3 2606:4700:4700::1111
curl -6 -sI https://www.google.com | head -1

Then test from another machine. Many home connections still lack IPv6, so use a second server, a phone on mobile data, or an online ping service, and connect to the server's address directly: ssh admin@2001:db8:10:20::2 or ping -6 2001:db8:10:20::2. Once that works, publish an AAAA record for your domain, covered in point a domain to your server.

Firewall both families

An address that works is also an address that can be reached. IPv6 has no NAT hiding services behind a router, so every listening port is exposed unless a firewall says otherwise.

UFW handles IPv6 when IPV6=yes is set in /etc/default/ufw, which is the Ubuntu default. Rules you add then cover both families, and sudo ufw status verbose lists the IPv6 copies marked (v6). Check that line before you trust the policy:

grep ^IPV6 /etc/default/ufw
sudo ufw status verbose

Do not block ICMPv6 wholesale. Neighbor discovery, which replaces ARP, and path MTU discovery both depend on it, and UFW's default rules already allow the messages they need. A provider firewall in front of the server needs IPv6 rules as well. In CloudSat's cloud firewall, an empty Sources field means anywhere on IPv4 and IPv6, so write explicit sources where you want a restriction.

Privacy addresses are for laptops

Desktop Ubuntu prefers temporary, randomly generated IPv6 addresses for outgoing connections so websites cannot track a device by its address. A server wants the opposite: one stable address that matches its DNS records and firewall rules elsewhere. Netplan leaves privacy extensions off unless ipv6-privacy: true is set, so leave that key out.

If you really need IPv6 off

Usually the better fix is the thing that breaks, such as a service that prefers an IPv6 route that does not work. If you must turn it off, do it on the public interface in Netplan and leave the loopback alone, because some software binds to ::1 and fails without it. Remove the IPv6 addresses and routes from the interface block and add two keys:

      accept-ra: false
      link-local: []

Apply it with sudo netplan try. The interface then carries no IPv6 address of any kind, while lo keeps ::1. Setting the disable_ipv6 sysctl by hand also works for a while, but systemd-networkd may reset it when it reconfigures the link, so the Netplan setting is the one that lasts.

If only package downloads suffer from a broken IPv6 path, force APT onto IPv4 instead with Acquire::ForceIPv4 "true"; in /etc/apt/apt.conf.d/99force-ipv4.

FAQ

Why does ping -6 say "Network is unreachable"?

The server has no IPv6 default route. Add the routes entry with your provider's gateway, or remove accept-ra: false if the provider announces the route with router advertisements.

Why does the server show two global IPv6 addresses?

Usually one is your static address and the other was built automatically from a router advertisement, because accept-ra is still on. Set accept-ra: false to keep only the static one, and check that no dhcp6: true line is left in the same block.

Should I use the whole /64 or a single address?

Give services one stable address and publish that in DNS. The rest of the prefix stays available for extra sites, containers or a VPN, but every address you add needs the same firewall attention.

Do servers need IPv6 if all my users have IPv4?

Not strictly, but many mobile networks are IPv6-first and reach IPv4-only sites through translation gateways. An AAAA record gives those users a direct path, and the server can reach IPv6-only services and mirrors.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.