Skip to main content

Web servers and networking · Beginner · 15 min

IPv6 basics for server admins

By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · Nginx 1.30.8 stable (nginx.org repo) · iproute2 6.19

You will read and shorten IPv6 addresses, tell link-local, unique local and global addresses apart on your Ubuntu 26.04 server, make Nginx answer on IPv6 as well as IPv4, open the firewall for both families and check the result with a small script.

On this page

Most cloud providers now give a server an IPv6 address next to its IPv4 one, often without being asked. That is good news for reach, but it brings a quiet failure: a site that works perfectly over IPv4 and is broken, slow or wide open over IPv6, because Nginx only listens on one family, the firewall only covers one, or the DNS record points somewhere nothing answers.

This tutorial covers what a server admin needs day to day. You learn to read and shorten addresses, what the prefix sizes mean, which kinds of address a server has, how it gets them, and how to make a web server, DNS and firewall work for both families. Along the way you build two small tools in ~/ipv6-demo/: a Python helper that explains any IPv6 address or prefix, and a script that checks a site over IPv4 and IPv6 separately.

Addresses in the examples use 2001:db8::/32, the range set aside for documentation. Replace them with your own where a step says so. Output from your server differs, so samples are "something like" what you will see.

Step 1 · Install the tools and read an IPv6 address

Install what the tutorial uses. Most of it is already on an Ubuntu server, and apt skips anything that is:

Bash
sudo apt-get update
sudo apt-get install -y python3 iproute2 iputils-ping curl bind9-dnsutils ufw

An IPv6 address is 128 bits, written as eight groups of four hexadecimal digits separated by colons. Each group is 16 bits. Written out in full, an address looks like this:

Text
2001:0db8:0041:0000:0000:0000:0000:0024

Nobody writes them that way. The short form follows three rules:

  1. Drop leading zeros in each group: 0db8 becomes db8, 0041 becomes 41, 0000 becomes 0.
  2. Replace one run of all-zero groups with ::. Use it on the longest run; if two runs are the same length, use it on the first. You can only use :: once, or the reader cannot tell how many zeros each one hides.
  3. Write the letters in lower case.

So the address above is 2001:db8:41::24. To expand a short form, count the groups you can see and fill the :: with enough 0 groups to make eight.

Rather than trust your arithmetic, build a helper that does it. Python's standard ipaddress module knows the rules:

Bash
mkdir -p ~/ipv6-demo
cat > ~/ipv6-demo/v6.py <<'EOF'
#!/usr/bin/env python3
"""Explain IPv6 addresses and prefixes.

  v6.py addr <address>[/len]     long form, short form, kind and network
  v6.py split <prefix> <len>     how many /len networks fit in <prefix>
"""
import ipaddress
import sys

KINDS = [
    ("::1/128", "loopback"),
    ("fe80::/10", "link-local"),
    ("fc00::/7", "unique local"),
    ("2001:db8::/32", "documentation"),
    ("ff00::/8", "multicast"),
    ("2000::/3", "global unicast"),
]


def kind(addr):
    for prefix, name in KINDS:
        if addr in ipaddress.ip_network(prefix):
            return f"{name} ({prefix})"
    return "other"


def show(text):
    if "/" not in text:
        text += "/64"
    iface = ipaddress.IPv6Interface(text)
    print(f"long:    {iface.ip.exploded}")
    print(f"short:   {iface.ip.compressed}")
    print(f"kind:    {kind(iface.ip)}")
    print(f"network: {iface.network}")


def split(prefix, new_len):
    net = ipaddress.IPv6Network(prefix)
    if new_len < net.prefixlen:
        sys.exit(f"/{new_len} is bigger than {net}")
    count = 2 ** (new_len - net.prefixlen)
    size = 2 ** (128 - new_len)
    first = int(net.network_address)
    print(f"{count} networks of /{new_len} in {net}")
    for i in range(min(count, 3)):
        print(f"  {ipaddress.IPv6Network((first + i * size, new_len))}")
    if count > 3:
        print("  ...")
        print(f"  {ipaddress.IPv6Network((first + (count - 1) * size, new_len))}")


if __name__ == "__main__":
    if len(sys.argv) == 3 and sys.argv[1] == "addr":
        show(sys.argv[2])
    elif len(sys.argv) == 4 and sys.argv[1] == "split":
        split(sys.argv[2], int(sys.argv[3]))
    else:
        sys.exit(__doc__)
EOF
chmod +x ~/ipv6-demo/v6.py
~/ipv6-demo/v6.py addr 2001:0db8:0041:0000:0000:0000:0000:0024

It prints:

Text
long:    2001:0db8:0041:0000:0000:0000:0000:0024
short:   2001:db8:41::24
kind:    documentation (2001:db8::/32)
network: 2001:db8:41::/64

Check it worked

Shorten 2001:0db8:0000:0000:0001:0000:0000:0001 on paper first, then check:

Bash
~/ipv6-demo/v6.py addr 2001:0db8:0000:0000:0001:0000:0000:0001

The short line is 2001:db8::1:0:0:1. There are two runs of two zero groups, so :: replaces the first one and the second stays as 0:0. If you wrote 2001:db8::1::1, that is the mistake the "only once" rule prevents.

Step 2 · Understand /64, /56 and /48

IPv6 uses the same slash notation as IPv4: the number after the slash says how many leading bits name the network. Three sizes cover almost everything you will see:

  • /64 is one network: one LAN, one VLAN, one cloud subnet. The last 64 bits identify a machine on it. Automatic addressing (SLAAC, next steps) only works on a /64, so do not cut a network smaller than that, even if it holds two servers.
  • /56 is a common allocation for a home or small site: 256 networks of /64.
  • /48 is a common allocation for an organisation or a data centre site: 65,536 networks of /64.

Some hosting providers give a single server a whole /64, others a /56, and a few only one /128 address. Check your provider's network page so you know what you can use.

Ask the helper how a /56 divides:

Bash
~/ipv6-demo/v6.py split 2001:db8:41::/56 64
Text
256 networks of /64 in 2001:db8:41::/56
  2001:db8:41::/64
  2001:db8:41:1::/64
  2001:db8:41:2::/64
  ...
  2001:db8:41:ff::/64

Only the fourth group changes, from 0 to ff. That is the 8 bits between /56 and /64. Planning on group boundaries like this keeps addresses readable: in a /48, the whole fourth group is yours to number subnets, so 2001:db8:41:10::/64 can be "web", 2001:db8:41:20::/64 "databases", and so on.

Unlike IPv4, there is no broadcast address and no shortage to manage: a /64 has more addresses than you will ever assign. The planning question is how many networks you need, not how many hosts fit in each.

Check it worked

Bash
~/ipv6-demo/v6.py split 2001:db8:41::/48 64 | head -n 1
~/ipv6-demo/v6.py split 2001:db8:41::/48 56 | head -n 1

The first line says 65536 networks of /64 and the second 256 networks of /56. So a /48 holds 256 sites of /56, and each of those holds 256 networks of /64.

Step 3 · Tell your server's addresses apart

A server with IPv6 has several addresses at once, each with a different job. List them:

Bash
ip -6 -br addr

On a cloud server you see something like:

Text
lo               UNKNOWN        ::1/128
ens3             UP             2001:db8:41::24/64 fe80::5054:ff:fe12:3456/64

The kinds you will meet:

  • Loopback ::1 is the server talking to itself, the IPv6 twin of 127.0.0.1.
  • Link-local fe80::/10 exists on every interface that has IPv6 switched on. It only works on the directly attached network and routers never forward it. Neighbour discovery and router advertisements use it, which is why your default gateway is often a link-local address such as fe80::1. Because the same fe80:: prefix is on every interface, using one needs the interface name too: fe80::1%ens3.
  • Unique local fc00::/7 (in practice always starting fd) is the IPv6 equivalent of private ranges such as 10.0.0.0/8. Use it for internal networks that never need to be reached from the internet, such as a private VPN.
  • Global unicast 2000::/3 is a public, routable address. This is the one that goes in DNS.

Feed every address on the server through the helper:

Bash
for a in $(ip -6 -o addr | awk '{print $4}'); do
  echo "== $a"
  ~/ipv6-demo/v6.py addr "$a" | grep -E '^(short|kind):'
done

ip -6 addr show (without -br) adds a scope word to each line: scope host for loopback, scope link for link-local and scope global for unique local and global addresses. The ip tutorial in Next steps covers the other fields.

Check it worked

The loop prints a kind line for each address. On a server with working public IPv6 you see at least loopback, one link-local and one global unicast. If you only see loopback and link-local, the server has IPv6 switched on but no public address: check your provider's console, where IPv6 is often a separate option per server.

Step 4 · See how the server got its address

There are two common ways a server gets a global IPv6 address:

  • SLAAC (stateless address autoconfiguration). The router sends out router advertisements naming the /64 prefix; the server picks the last 64 bits itself and adds a default route through the router. Nothing on the server needs configuring.
  • Static. You write the address and the gateway into Netplan. Many dedicated-server and VPS providers expect this and tell you the address, prefix and gateway in their control panel.

ip shows which one you have. Look at the details for your global address and at the default route:

Bash
ip -6 addr show scope global
ip -6 route show default

Something like this, for SLAAC:

Text
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 2001:db8:41::24/64 scope global dynamic mngtmpaddr noprefixroute
       valid_lft 86321sec preferred_lft 14321sec
default via fe80::1 dev ens3 proto ra metric 100 expires 1795sec pref medium

dynamic with counting-down lifetimes and proto ra on the route mean the address and gateway came from router advertisements. A static address shows valid_lft forever and the route shows proto static.

A static setup in Netplan looks like this. Replace the address and gateway with the ones from your provider; the Netplan tutorial in Next steps shows how to test and apply such a file safely, because a mistake here can cut off your SSH session:

YAML
network:
  version: 2
  ethernets:
    ens3:
      accept-ra: false
      addresses:
        - 2001:db8:41::24/64
      routes:
        - to: "::/0"
          via: "2001:db8:41::1"

Whichever way you got there, check that IPv6 is switched on and that the stack answers. 0 means enabled:

Bash
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
ip -6 route get ::1
ping -6 -c 3 ::1

Check it worked

ip -6 route get ::1 names dev lo, and the ping reports 3 packets transmitted, 3 received. On your server, ip -6 route show default prints one default via line. If it prints nothing, the server has a global address but no way out, and outgoing IPv6 connections will fail.

Step 5 · Make Nginx listen on IPv6

A very common gap: Nginx answers on IPv4 only, because the server block has listen 80; and nothing for IPv6. In Nginx, listen 80; means IPv4 only, and listen [::]:80; means IPv6 only (the ipv6only option is on by default). A site that should answer on both needs both lines.

Add a small demo site on port 8086, so it does not interfere with anything you already serve. It answers with the address the request came from, which shows which family each request used:

Bash
sudo tee /etc/nginx/conf.d/ipv6-demo.conf > /dev/null <<'EOF'
server {
    listen 8086;
    listen [::]:8086;
    default_type text/plain;
    return 200 "ipv6-demo: you connected from $remote_addr\n";
}
EOF
sudo nginx -t

Test passed, so reload:

Bash
sudo systemctl reload nginx

Confirm Nginx is listening on both families:

Bash
ss -ltn 'sport = :8086'

Something like:

Text
State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port
LISTEN  0       511            0.0.0.0:8086        0.0.0.0:*
LISTEN  0       511               [::]:8086           [::]:*

0.0.0.0 is every IPv4 address and [::] is every IPv6 address. IPv6 addresses in URLs and host:port pairs go in square brackets, because the address itself contains colons.

For your real sites, add listen [::]:80; under listen 80;, and listen [::]:443 ssl; under listen 443 ssl;, in each server block.

Check it worked

Call the demo site over each family. -g stops curl reading the square brackets as a pattern:

Bash
curl -4 -sS http://127.0.0.1:8086/
curl -6 -sS -g 'http://[::1]:8086/'

The first line ends you connected from 127.0.0.1 and the second you connected from ::1. If the second fails with Connection refused, the listen [::]:8086; line is missing or Nginx was not reloaded.

Step 6 · Publish an AAAA record

DNS has a separate record type for IPv6. An A record points a name at an IPv4 address, an AAAA record at an IPv6 address. A name can have both, and most clients then try IPv6 first and fall back to IPv4 if it fails.

Look at a name that has both:

Bash
dig +short A one.one.one.one
dig +short AAAA one.one.one.one

The AAAA query returns 2606:4700:4700::1111 and 2606:4700:4700::1001.

At your DNS provider, add an AAAA record for your site's name with your server's global address from the earlier step, next to the existing A record. Something like:

Text
www.example.com.   3600   IN   A      203.0.113.24
www.example.com.   3600   IN   AAAA   2001:db8:41::24

Add it only after Nginx listens on IPv6 and the firewall allows it (next step). A broken AAAA record is worse than none: clients with IPv6 try it first, and visitors see either a slow page while their browser waits before falling back, or an error.

Check it worked

Replace www.example.com with your name:

Bash
dig +short AAAA www.example.com

The answer is your server's global IPv6 address. Records take up to the TTL (3600 seconds in the example) to replace an old cached answer, so an empty result straight after adding a new record can just mean waiting.

Step 7 · Cover both families in the firewall

UFW keeps separate rule sets for IPv4 and IPv6 and applies each rule to both, but only when IPv6 support is on in its settings. Check:

Bash
grep '^IPV6=' /etc/default/ufw

It prints IPV6=yes, the Ubuntu default. If it says no, every rule you add only protects IPv4, while IPv6 traffic is handled by whatever else is (or is not) filtering it. Change it to yes with sudo nano /etc/default/ufw, then run sudo ufw reload.

Allow web traffic. One command adds both an IPv4 and an IPv6 rule:

Bash
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

The output ends with a line marked (v6) for each, such as Rule added (v6), or Rules updated (v6) if UFW is not enabled yet. If UFW is not enabled, do not enable it until you have allowed SSH as well: the UFW tutorial in Next steps walks through that in a safe order. On an active firewall, check the rules:

Bash
sudo ufw status

Something like:

Text
To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)

Three more things to know:

  • Do not block all ICMPv6. IPv6 depends on it for neighbour discovery (its version of ARP), router advertisements and telling senders a packet is too big. UFW's default rules already allow the types that matter. If you write your own rules, follow the nftables tutorial, where an inet table covers both families with one rule set.
  • Cloud firewalls list the two families separately. In most providers' security groups, a source of 0.0.0.0/0 means all of IPv4 only; you need a second rule with ::/0 for IPv6.
  • There is no NAT hiding the server. On IPv4, many internal machines sit behind NAT and cannot be reached from outside even without a firewall. Over IPv6 each one can have a public address, so the firewall is the only thing deciding what is reachable.

Check it worked

sudo ufw status lists every port you allow twice, once plain and once with (v6). Any port with only the plain line is open on IPv4 and closed, or unfiltered, on IPv6.

Step 8 · Check the site from outside over each family

Tests from the server itself prove Nginx is listening. They do not prove the internet can reach it: the cloud firewall, the provider's routing or a missing AAAA record only show up from another machine. This script asks the same URL over IPv4 and over IPv6 separately and reports each:

Bash
cat > ~/ipv6-demo/check-both.sh <<'EOF'
#!/usr/bin/env bash
# Usage: check-both.sh <hostname> [port]
# Requests http://<hostname>:<port>/ over IPv4 and over IPv6 separately.
set -uo pipefail
host=$1
port=${2:-80}
status=0
for fam in 4 6; do
  if out=$(curl -"$fam" -sS -o /dev/null --max-time 10 \
      -w '%{http_code} from %{remote_ip}' "http://$host:$port/" 2>&1); then
    echo "IPv$fam: ok    $out"
  else
    echo "IPv$fam: FAIL  $out"
    status=1
  fi
done
exit "$status"
EOF
chmod +x ~/ipv6-demo/check-both.sh
~/ipv6-demo/check-both.sh localhost 8086

On the server it prints:

Text
IPv4: ok    200 from 127.0.0.1
IPv6: ok    200 from ::1

Now run it from somewhere else. The script is plain Bash and curl, so it runs on macOS and Linux. Copy it to your laptop, or to a second server, and point it at your real site. On your laptop:

Bash
curl -6 -sS -o /dev/null -w '%{remote_ip}\n' https://one.one.one.one/
bash check-both.sh www.example.com

The first command tells you whether your own connection has IPv6. If it fails, an IPv6: FAIL line from the script says nothing about your server: many home, office and mobile connections are still IPv4 only. That is common on prepaid mobile data in parts of Africa, where a phone often reaches the internet through the operator's shared IPv4 addresses. Run the check from a second server with IPv6 instead, and keep IPv4 working for those visitors: IPv6 is an addition, not a replacement.

Check it worked

From a machine with IPv6, both lines say ok with a 200 (or the 301 your site sends to redirect to HTTPS), and the IPv6 line shows your server's global address. If IPv4 works and IPv6 times out, check in this order: the AAAA record, the provider's cloud firewall for ::/0, UFW's (v6) rules, then Nginx's listen [::]: lines.

When you are done, remove the demo site and the helper folder. Keep the ufw allow rules if your server serves web traffic; if it does not, remove them with sudo ufw delete allow 80/tcp and sudo ufw delete allow 443/tcp:

Bash
sudo rm /etc/nginx/conf.d/ipv6-demo.conf
sudo nginx -t
rm -r ~/ipv6-demo
Bash
sudo systemctl reload nginx

Next steps

Your server now answers on IPv6 as well as IPv4, its firewall covers both, and you can tell from outside which family works.

  • Read every field ip shows for addresses and routes: /tutorials/see-addresses-and-routes-with-the-ip-command
  • Compare with IPv4 prefixes and subnet plans: /tutorials/understand-ip-addresses-subnets-and-cidr
  • Set a static IPv6 address and gateway safely: /tutorials/configure-a-static-ip-with-netplan
  • Turn on UFW without locking yourself out: /tutorials/set-up-ufw-firewall-ubuntu-26-04

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.