Sub topic 14
Carrier-grade NAT and why port forwarding may not work
This chapter assumes you know IPv4 private ranges, how source NAT and PAT use a translation table, how destination NAT forwards a port, and how to read iptables or nft output. It explains why a correct port forward on your router can still fail when your internet provider runs NAT too.
What carrier-grade NAT is
Carrier-grade NAT (CGNAT, also called large-scale NAT or LSN) is source NAT run by an internet service provider (ISP) on its own network. The provider puts many customers behind a small pool of public IPv4 addresses. The reason is the same as for home NAT: there are not enough public IPv4 addresses for every subscriber.
The result is two layers of NAT in a row. Your home router translates your LAN addresses to one address. The provider's CGNAT then translates that address to a public one.
The shared address space 100.64.0.0/10
The three private ranges from RFC 1918 (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) are used inside homes and companies. If an ISP also used them between the customer and the CGNAT, the ranges could overlap with the customer's own LAN. Routing would then be ambiguous.
RFC 6598 solves this by reserving 100.64.0.0/10, called the shared address space. It is meant only for the link between a subscriber and the provider's CGNAT. It is not a public range, and it is not one of the RFC 1918 ranges, so it does not collide with a home LAN. Routers should not forward it to the public internet.
Typical flow of addresses:
| Segment | Example address | Who controls it |
|---|---|---|
| Laptop | 192.168.1.20 | You |
| Home router LAN side | 192.168.1.1 | You |
| Home router WAN side | 100.64.12.7 | ISP (shared space) |
| Public address seen by servers | 198.51.100.9 | ISP (shared by many customers) |
Some providers use other ranges on the WAN side, for example RFC 1918 space or even public space they do not own. The 100.64.0.0/10 range is the common and correct choice.
Why port forwarding fails behind CGNAT
A port forward works because of a destination NAT rule on the device that owns the public address. When you forward port 8080 on your home router, the router rewrites incoming packets to your internal server. For that to work, outside clients must be able to send packets to your router's WAN address.
Behind CGNAT, your router's WAN address is a 100.64.x.x address. Nobody on the internet can reach it. The packets arrive at the ISP's public address 198.51.100.9 instead, and that address is shared by many customers. The CGNAT has no translation table entry for an unsolicited inbound packet, so it drops the packet.
Your own rule on the home router is correct and can look healthy in iptables -t nat -L -n -v. The failure is outside your control. Three more details make it worse:
- The ISP's CGNAT port range is shared. Even if you could ask for a port, many customers need the same well-known ports such as 80 and 443.
- CGNAT mappings are usually created only by outbound traffic. This matches the endpoint-dependent filtering described in the chapter on NAT behaviors.
- Mappings expire. Idle UDP and TCP flows are removed after a timeout, often shorter than on a home router.
How to tell whether you are behind CGNAT
Compare the WAN address your router reports with the public address that internet servers see.
- Open your router's status page and read the WAN (internet) IPv4 address.
- From a machine on your LAN, ask an external service for your public address.
- If the two addresses differ, a NAT device sits between you and the internet.
# Public IPv4 address as seen by an external service
curl -4 https://ifconfig.me
echo
# Trace the path and look for a 100.64.0.0/10 hop or private hop
traceroute -n 1.1.1.1Signs of CGNAT:
- The router's WAN address is in 100.64.0.0/10 (100.64.0.0 to 100.127.255.255).
- The router's WAN address is in an RFC 1918 range.
- The WAN address differs from the public address, and the early traceroute hops are private or shared addresses.
- The public address changes often, or the same public address appears for unrelated customers.
A differing address is a strong hint but not proof, because your router might sit behind a modem that does its own NAT, or you might be using a VPN. Check the router's WAN address first.
Effects other than port forwarding
CGNAT also changes how other things behave:
- Shared reputation. Many customers share one public address. If one of them is blocked for abuse, others can be blocked as well.
- Logging. Identifying a user needs the public address, the source port, and a timestamp, because the address alone matches many customers.
- Port exhaustion. A provider assigns each subscriber a limited number of ports on the shared address, often a block of a few thousand. A client that opens many connections can run out, and new connections then fail.
- Peer-to-peer and gaming. Direct connections between two users behind CGNAT often fail, because hole punching depends on the NAT's mapping and filtering behavior. Symmetric or port-restricted behavior can force traffic through a relay.
- Hairpinning at the provider. Two customers behind the same CGNAT may be unable to reach each other by their public address unless the CGNAT supports hairpinning.
Options when you are behind CGNAT
You cannot fix this with a different rule on your home router. The practical options are:
| Option | How it works | Trade-off |
|---|---|---|
| Ask the ISP for a public IPv4 address | Many ISPs offer a public address, sometimes as a paid add-on or on request | Cost, and not every ISP offers it |
| Use IPv6 | Hosts get globally routable addresses, so a firewall rule replaces port forwarding | Needs IPv6 from the ISP, and clients must have IPv6 |
| Reverse tunnel to a public host | Your server opens an outbound connection to a rented server with a public address, which relays inbound traffic | Added latency, a server to run, and a trusted relay |
| VPN with a public endpoint | A VPN provider or your own VPS forwards ports to you | Same relay costs, and you must secure the exposed port |
| Cloud tunnel service | A hosted service accepts traffic and delivers it over an outbound connection | Third party sees or handles your traffic metadata |
| Peer-to-peer traversal | STUN and hole punching in the application | Works only for some NAT behavior combinations |
The reverse tunnel pattern works because the connection that creates the mapping starts from inside. The CGNAT sees an ordinary outbound flow, so inbound data on that flow is allowed.
Here is a small example. A rented server with public address 203.0.113.50 forwards its port 8080 to your home server through an SSH tunnel that your home machine opens.
# Run on the home machine (behind CGNAT).
# -N: no remote command, -R: remote port 8080 on the VPS forwards to local port 80
ssh -N -R 0.0.0.0:8080:127.0.0.1:80 [email protected]On the rented server, SSH must allow remote forwards to bind to all interfaces:
# /etc/ssh/sshd_config on the rented server needs this line:
# GatewayPorts clientspecified
sudo sshd -t && sudo systemctl reload sshClients then connect to http://203.0.113.50:8080/. If the home connection drops, the tunnel closes, so production setups use a supervisor such as autossh or a systemd service to restart it.
CGNAT and IPv6
CGNAT delays the exhaustion problem but adds cost, state, and breakage for the provider. IPv6 removes the need for address sharing because every subscriber gets a large routable prefix. Many ISPs run dual-stack: IPv6 end to end, plus CGNAT only for IPv4. In that setup, a service reachable over IPv6 can be exposed without any port forward, as long as the router's IPv6 firewall allows the inbound traffic.
Common errors
- Debugging the home router for hours. If the WAN address is in 100.64.0.0/10, the router rule is not the problem.
- Testing from inside the LAN. An internal test does not exercise the CGNAT path. Always test from a host outside your network, as in the troubleshooting chapter.
- Using a UPnP or NAT-PMP mapping and expecting it to work. Those protocols only configure your home router. They cannot open a port on the ISP's CGNAT.
- Assuming the public address is yours. Looking up the address you see online and forwarding to it can point at another customer's connection or a shared address.
Exercise
Your router's status page shows a WAN IPv4 address of 100.71.4.18, but an external website reports your address as 198.51.100.9. You configured a correct DNAT rule for port 8080 and testing from a mobile network fails. Explain why, and name two ways to get inbound access.
Show answer
The 100.64.0.0/10 address means the ISP runs carrier-grade NAT. Your router's WAN address is not reachable from the internet, and the CGNAT drops unsolicited inbound packets because no translation entry exists. Your DNAT rule is never reached. Two ways to get inbound access are to ask the ISP for a public IPv4 address, or to open an outbound reverse tunnel (for example SSH -R or a VPN) to a public server that relays traffic to you. Using IPv6, if the ISP offers it, also works.
Exercise
Why can a UPnP port mapping on your home router not fix a CGNAT problem?
Show answer
UPnP only asks your own router to create a destination NAT rule. The second NAT layer is run by the ISP, and your router cannot configure it. Inbound packets are dropped at the CGNAT before they ever reach your router.