Sub topic 15
NAT and IPv6
This chapter covers how IPv6 changes the reasons for using NAT. It assumes you know IPv4 NAT from the earlier chapters: source NAT and PAT, port forwarding, the translation table, and carrier-grade NAT (CGNAT). You should also be comfortable with prefixes and with running commands in a Linux shell.
Why IPv6 removes the main reason for NAT
IPv4 NAT exists because public addresses ran out. A home or office network gets one public address, or a few. NAT lets many private hosts share it by rewriting addresses and ports, and the translation table remembers who owns each flow.
IPv6 addresses are 128 bits long. A typical home or small-office connection receives a whole prefix, often a /56 or /64 or larger. A /64 alone holds about 1.8 × 10^19 addresses. Every device can have a globally routable address, so no sharing is needed.
This changes the picture in three ways:
- No address sharing. Hosts talk to the internet using their own addresses. The router forwards packets and does not rewrite them.
- End-to-end addressing. A remote peer can send a packet straight to a device's global address. Protocols that embed addresses in their payload, or need inbound connections, no longer need helpers or traversal tricks.
- No port forwarding for reachability. A server already has a public address. You decide whether outside hosts may reach it by writing a firewall rule, not a translation rule.
The following diagram contrasts the two paths.
NAT is not a firewall, and IPv6 needs one
A common belief is that NAT protects hosts. The protection people see is a side effect. A NAT device drops unsolicited inbound packets because it has no translation entry to map them to. That is stateful filtering, and a stateful firewall provides the same behavior without rewriting any address.
With IPv6 you keep the filtering and drop the rewriting. If you remove NAT and add no firewall, every internal host becomes reachable from the whole internet. A correct IPv6 edge router therefore has a default policy like this:
- Allow outbound connections from the LAN.
- Allow inbound packets that belong to established or related connections.
- Drop other new inbound connections, except those you explicitly allow.
- Allow the ICMPv6 types that IPv6 needs to work (see below).
Here is a minimal ip6tables version for a Linux router, where eth0 is the WAN interface and eth1 is the LAN interface:
# Allow the Linux host to forward IPv6 packets
sudo sysctl -w net.ipv6.conf.all.forwarding=1
# Default: drop forwarded traffic unless allowed
sudo ip6tables -P FORWARD DROP
# Allow replies to connections that already exist
sudo ip6tables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow the LAN to start connections to the outside
sudo ip6tables -A FORWARD -i eth1 -o eth0 -j ACCEPT
# Allow essential ICMPv6 errors such as Packet Too Big
sudo ip6tables -A FORWARD -p ipv6-icmp -j ACCEPTNotice what is missing. There is no nat table and no MASQUERADE rule. The firewall decides who may connect, and nothing is translated.
To publish a service, you permit it on its real address. This replaces the DNAT and FORWARD pair from the IPv4 port forwarding chapter:
# Allow outside clients to reach the web server at its own global address
sudo ip6tables -A FORWARD -i eth0 -o eth1 -d 2001:db8:1:1::10 -p tcp --dport 443 -j ACCEPTClients connect to port 443 on 2001:db8:1:1::10. The port number does not change and the address does not change. This is a rule about permission, not about translation.
Where translation still appears with IPv6
IPv6 reduces the need for NAT, but several translation mechanisms still exist. They solve different problems, so keep them apart.
| Mechanism | What it does | Typical use |
|---|---|---|
| NAT64 | Translates IPv6 packets to IPv4 packets at a gateway | An IPv6-only network that must reach IPv4-only servers |
| DNS64 | Synthesizes AAAA records from A records, using a NAT64 prefix | Works with NAT64 so IPv6-only clients use the gateway automatically |
| 464XLAT | Combines a client-side translator (CLAT) with provider-side NAT64 (PLAT) | Mobile networks serving apps that use IPv4 literals |
| NPTv6 | Translates one IPv6 prefix to another, one to one, without changing ports | Multihoming and prefix independence |
| NAT66 (masquerade) | Rewrites an IPv6 source address to the router's address, like IPv4 PAT | Rare. Sometimes used when an upstream provides only a single address |
NAT64 and DNS64
NAT64 sits between an IPv6-only network and the IPv4 internet. It uses a special prefix, usually 64:ff9b::/96. DNS64 takes an IPv4 address from an A record and embeds it in that prefix, which produces a synthetic IPv6 address. The client connects to that address, the packet reaches the NAT64 gateway, and the gateway extracts the IPv4 address and sends an IPv4 packet using its own IPv4 address. It keeps a translation table, much like PAT.
For example, 93.184.216.34 becomes 64:ff9b::5db8:d822, because the four bytes of the IPv4 address are written in hexadecimal at the end of the prefix.
You can check how DNS64 behaves by asking for the AAAA record of an IPv4-only name:
# On an IPv6-only network with DNS64, an IPv4-only host still returns AAAA
dig AAAA ipv4only.arpa +shortThe special name ipv4only.arpa has only A records on the real internet. A synthesized answer inside the NAT64 prefix means DNS64 is working.
NPTv6 and NAT66
NPTv6 (RFC 6296) swaps the prefix portion of an address and keeps the rest. It is stateless, so it needs no translation table. It also preserves the end-to-end checksum properties, because the translator adjusts bits in the address to cancel the checksum change. It does not change ports, so it does not hide many hosts behind one address.
NAT66 using masquerading does work on Linux, but it brings back the problems of IPv4 NAT: the translation table, broken inbound reachability, and applications that embed addresses. Most designs avoid it. If you need network independence from a provider's prefix, the usual answer is to get provider-independent address space or to use NPTv6.
Operational differences you will meet
IPv6 changes more than NAT. These points are the common stumbling blocks for people who know IPv4 NAT.
Address stability and privacy
Without NAT, a device's global address identifies it. To limit tracking, operating systems use temporary addresses (privacy extensions, RFC 8981). These change over time and are used for outbound connections. A stable address is still needed for servers. Firewall rules and DNS records should refer to the stable address, not a temporary one.
Prefix changes
Many residential providers change your delegated prefix after a reconnect. With IPv4 NAT, the private addresses stayed constant behind the router, so only the single public address changed. With IPv6, every host address changes. Plan for this:
- Use DNS with short TTLs or dynamic DNS for services.
- Use unique local addresses (ULA,
fd00::/8) for internal traffic that must stay stable. - Avoid hard-coding global addresses in configuration where you can use names.
ULA addresses are not routable on the internet. They play the same role as private IPv4 addresses for internal communication, but you do not translate them for internet access. Hosts normally have both a ULA and a global address and choose between them by destination.
ICMPv6 must not be blocked
IPv6 routers do not fragment packets. Path MTU discovery relies on ICMPv6 "Packet Too Big" messages. Neighbor discovery and router advertisements use ICMPv6 too. A rule that drops all ICMP, which some IPv4 admins use, breaks IPv6 in subtle ways. Large transfers stall while small ones succeed. That symptom looks like a black hole and is hard to diagnose unless you remember this rule.
CGNAT and IPv6
Earlier you saw that CGNAT blocks port forwarding because the provider, not you, controls the public address. If the same provider offers native IPv6, you can often reach your home services over IPv6 even when IPv4 is behind CGNAT. The service needs an AAAA record and a firewall rule that permits inbound connections. Only IPv6 clients, or clients with IPv6 access, can connect that way.
Checking your own setup
Use these commands to see what your host has:
# List global IPv6 addresses
ip -6 addr show scope global
# Show the IPv6 default route
ip -6 route show default
# Confirm outbound IPv6 works and see which address the server sees
curl -6 https://ifconfig.coIf curl -6 prints an address that matches one on your host, nothing is rewriting your traffic. If it prints something different, a translator such as NAT66 is in the path.
Dual-stack in practice
Most networks run IPv4 and IPv6 together. The host prefers IPv6 when both are available, following the address selection rules in RFC 6724 and, for connection attempts, the "Happy Eyeballs" algorithm that races both families. The result is that a user's traffic often uses IPv6 without any visible sign, while IPv4 still passes through NAT. When troubleshooting a dual-stack network, always identify which address family a failing connection uses. A port forward that works for IPv4 tells you nothing about IPv6, because the IPv6 path needs a firewall rule instead.
Exercise
A small office moves to IPv6. The administrator removes the MASQUERADE rule and sets no IPv6 firewall rules, with the FORWARD policy left at ACCEPT. Staff can browse normally. Explain what has changed for the internal hosts, and write the ip6tables policy and rules that restore the protection NAT used to provide by accident, while still allowing LAN users to browse.
Show answer
Without NAT, each host keeps its global address, and the open FORWARD policy lets any outside host start connections to them, so listening services are reachable from the internet. NAT used to block this only because unsolicited inbound packets had no translation entry. A firewall provides the same effect: set the policy with ip6tables -P FORWARD DROP, allow replies with ip6tables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT, and allow the LAN with ip6tables -A FORWARD -i eth1 -o eth0 -j ACCEPT. Also allow ICMPv6 with ip6tables -A FORWARD -p ipv6-icmp -j ACCEPT so path MTU discovery keeps working.
Exercise
An IPv6-only client reaches an IPv4-only website through DNS64 and NAT64. The site's A record is 192.0.2.10, and the NAT64 prefix is 64:ff9b::/96. What address does the client connect to, and which device converts the packet to IPv4?
Show answer
192.0.2.10 is c000:020a in hexadecimal (192 = c0, 0 = 00, 2 = 02, 10 = 0a), so the client connects to 64:ff9b::c000:20a. The NAT64 gateway receives the packet, extracts the IPv4 address from the last 32 bits, and sends an IPv4 packet to 192.0.2.10 using its own IPv4 address. It records the mapping in its translation table so the reply can be translated back to IPv6.
Exercise
A home server is reachable by IPv4 port forwarding, but a friend with IPv6 cannot connect to the server's AAAA address. Name two things to check on the router.
Show answer
Check that the router's IPv6 forwarding policy has a rule that permits inbound TCP to the server's global address and the service port, because the default-deny policy drops new inbound connections. Also check that the AAAA record holds the server's current address, because the ISP may have changed the delegated prefix after a reconnect.