Sub topic 15
NAT and IPv6
This chapter assumes you know how source NAT, port address translation (PAT), and port forwarding work. It also assumes you know what carrier-grade NAT (CGNAT) is and can read basic iptables rules.
Why IPv6 removes the need for NAT
NAT exists because IPv4 has about 4.3 billion addresses, which is too few. IPv6 uses 128-bit addresses, so every device can have a globally unique address. A typical home network gets a /56 or /64 prefix from its provider, and each host builds its own global address inside it.
Because every host has its own routable address, a router doesn't need to rewrite addresses or ports. Packets keep their original source and destination from end to end. This restores the end-to-end model that NAT broke. The protocol problems from earlier chapters (embedded addresses, hole punching, helpers) mostly disappear.
NAT is not a firewall
Many people believe NAT protects hosts, because unsolicited inbound packets have no translation entry and get dropped. That drop is a side effect. The actual protection comes from the filtering rules.
An IPv6 router gives the same protection with a stateful firewall. It allows outbound connections, allows replies that match tracked state, and drops new inbound connections. This is the default on most consumer routers, and RFC 6092 recommends it.
Port forwarding has an IPv6 equivalent called a pinhole. You don't rewrite the destination. You permit new inbound connections to one host's address and port.
# Router: enable IPv6 forwarding
sudo sysctl -w net.ipv6.conf.all.forwarding=1
# Drop forwarded traffic by default, but allow replies to outbound connections
sudo ip6tables -P FORWARD DROP
sudo ip6tables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Path MTU discovery needs this ICMPv6 message to cross the router
sudo ip6tables -A FORWARD -p icmpv6 --icmpv6-type packet-too-big -j ACCEPT
# Pinhole: allow new HTTPS connections from eth0 to one internal server
sudo ip6tables -A FORWARD -i eth0 -p tcp -d 2001:db8:1::10 --dport 443 -m conntrack --ctstate NEW -j ACCEPTThe address 2001:db8:1::10 is from the documentation range. Replace it with your server's real global address.
Where translation still appears with IPv6
IPv6 does not eliminate translation entirely. These cases remain:
| Mechanism | What it does | Typical use |
|---|---|---|
| NAT64 with DNS64 | Lets IPv6-only clients reach IPv4-only servers | Mobile and IPv6-only networks |
| 464XLAT | Translates IPv4 apps on the client, then NAT64 in the carrier | Mobile phones running IPv4-only apps |
| NPTv6 (RFC 6296) | Swaps the prefix one-to-one and leaves the host part unchanged | Multihoming, renumbering |
| NAT66 (masquerade) | Many-to-one translation as in IPv4 | Rare, usually a workaround |
NAT64 is the most important one. The DNS64 resolver invents an AAAA record for an IPv4-only name by embedding the IPv4 address in a special prefix, usually 64:ff9b::/96. The client sends IPv6 traffic to that address, and the NAT64 gateway translates it into IPv4.
NAT66 and unique local addresses
IPv6 has private-style addresses called unique local addresses (ULA, fc00::/7, in practice fd00::/8). They are not routed on the internet, and they are useful for stable internal addressing. Hosts normally use them alongside a global address, so you don't translate between them.
NAT66 is discouraged because it brings back the old problems for little benefit. If you want privacy, use temporary addresses (RFC 4941). If you want stable internal addresses, use ULA.
CGNAT and the transition
Providers use CGNAT because they lack IPv4 addresses. A customer on dual stack gets a real IPv6 address even when the IPv4 address is shared. Inbound IPv6 connections can then reach the customer, so a pinhole works where IPv4 port forwarding does not. This is the practical reason to enable IPv6 when your provider uses CGNAT.
Exercise
Your ISP puts you behind CGNAT, so IPv4 port forwarding to your home web server fails. Your router also has a global IPv6 prefix. What do you configure to make the server reachable over IPv6, and why is NAT not involved?
Show answer
Add a firewall rule (a pinhole) on the router that allows new inbound TCP connections to the server's global IPv6 address on the service port, with a stateful rule for replies. Every host has a unique routable address, so no address or port rewriting is needed. You only permit traffic that the default-deny firewall would otherwise drop.