December 5, 2026

Port Forwarding, NAT and CGNAT Explained: Why the Rule Is Correct and the Server Still Can’t Be Reached

A home router on a shelf connected to a wall jack

A home server, a port forwarding rule copied carefully from a guide, and a friend on the other side of town who still gets nothing. Sometimes the rule is wrong. More and more often, the rule is perfect and the problem sits one level up, inside the internet provider’s network, where a second layer of address translation throws away every incoming connection before it reaches the home router. To show exactly where the line falls, a miniature internet was built on one Linux machine using network namespaces, with a home router, a PC running a web server, an internet host, and, in the second test, a provider-level NAT in between.

Video: Lawrence Systems on YouTube

Why home networks use NAT at all

Private addresses

Most home devices have addresses like 192.168.1.10 that are never seen on the internet. RFC 1918 reserves three blocks for private networks: 10.0.0.0 to 10.255.255.255, 172.16.0.0 to 172.31.255.255, and 192.168.0.0 to 192.168.255.255. Millions of homes reuse the same ranges, so these addresses cannot be routed on the public internet.

Translation on the way out

The router holds the household’s one public address. When the PC opens a connection outward, the router rewrites the source address to its own and keeps a table entry so replies can be sent back to the right device. Outbound connections therefore just work. Inbound connections are another matter: a packet arriving at the public address for a port nobody asked about has no table entry, and the router has no idea which device, if any, should get it.

Office lobby

Port forwarding, tested

The lab

The first network had three parts, each in its own namespace on the same Linux machine:

  • an “internet” host at 203.0.113.10, running a small web page that reports the address it sees,
  • a home router with a public WAN address of 203.0.113.2 and a LAN address of 192.168.1.1,
  • a PC at 192.168.1.10, running a web server on port 8080.

The 203.0.113.0/24 range is reserved for documentation and examples, which makes it safe to use in a lab. The router got two rules in its firewall: masquerade (rewrite) outgoing traffic to its WAN address, and forward incoming TCP port 8080 to the PC:

iptables -t nat -A POSTROUTING -o r0 -j MASQUERADE
iptables -t nat -A PREROUTING -i r0 -p tcp --dport 8080 -j DNAT --to-destination 192.168.1.10:8080

Results

router WAN address: 203.0.113.2/24
outbound from pc: internet sees you as 203.0.113.2
inbound from internet to 203.0.113.2:8080: pc sees you as 203.0.113.10

Outbound, the internet saw the router’s public address, not the PC’s private one. Inbound, a request to the router’s public address on port 8080 landed on the PC, which saw the real internet host as the client. The port forward did exactly what home router menus call “virtual server” or “port forwarding”: it gave one internal service a permanent entry in the translation table.

CGNAT: the second layer

Shared address space

When providers ran short of IPv4 addresses, many began giving customers’ routers private-style addresses and doing the translation to public addresses inside their own networks. This is carrier-grade NAT. RFC 6598, published in April 2012, set aside 100.64.0.0/10 as Shared Address Space for this purpose, numbering the links between a provider’s CGN devices and customers’ equipment. The RFC calls it distinct from RFC 1918 private space because it is meant for provider networks, and says packets with these addresses must not be forwarded across provider boundaries.

The same test, with a provider in the middle

The second network added an “ISP” namespace between the internet and the home router. The ISP held the public address 203.0.113.2 and gave the home router 100.64.0.2, masquerading everything from 100.64.0.0/10. The home router kept exactly the same two rules as before. Results:

router WAN address: 100.64.0.2/24
outbound from pc: internet sees you as 203.0.113.2
inbound from internet to 203.0.113.2:8080: FAIL (no answer)

Outbound still worked, through two layers of translation. The internet host saw 203.0.113.2, the provider’s address, not the home router’s 100.64.0.2. In a real deployment, many households sit behind each such public address, which is why a CGNAT customer can be hit by a website’s block or a run of CAPTCHAs triggered by a neighbor’s traffic.

Inbound failed. The request for port 8080 reached the provider’s NAT, which had no forwarding rule and no table entry, and went no further. The home router’s forward was never consulted, because the packet never reached it.

House entrance

How to tell which situation applies

Compare two addresses

The test shows the giveaway. Under CGNAT, the router’s own WAN address differs from the address an IP lookup website reports:

Router’s WAN address Address the internet sees Situation
Matches the website Same Public address: port forwarding can work
In 100.64.0.0 to 100.127.255.255 Different CGNAT: port forwarding on the home router cannot work
In 10.x, 172.16-31.x or 192.168.x Different Another router or provider NAT upstream

The router’s WAN address is usually on its status page. The third row also covers a common home mistake: a provider-supplied modem that is itself a router, with a second router behind it. That double NAT is fixable at home by putting the provider’s box in bridge mode or forwarding the port on both devices.

Other clues

Mobile broadband, fixed wireless and many fiber and satellite services commonly use CGNAT. Game consoles reporting a “strict” or “type 3” NAT, and remote-access apps that only work over the provider’s relay and never directly, are both typical symptoms.

Getting in from outside anyway

Turn the connection around

CGNAT blocks connections that start outside. It does not block connections that start inside. That is the basis of nearly every workaround. To prove it, the PC behind both layers of NAT opened an outbound SSH connection to the internet host with a remote forward:

ssh -N -R 9000:localhost:8080 root@203.0.113.10

Then, on the internet host:

$ curl http://127.0.0.1:9000/
pc served this; it sees the client as 127.0.0.1

The web server behind CGNAT answered a request made on the internet side. The tunnel, opened from inside, carried the request back through both NATs as reply traffic on a connection the provider already knew about. The PC saw the request arriving from its own end of the tunnel, 127.0.0.1, rather than the original client.

Practical versions of the same idea

  • A small cloud server with WireGuard or SSH, where the home machine connects out and the cloud server’s public address becomes the front door.
  • Mesh VPNs such as Tailscale or ZeroTier, which connect devices peer to peer and fall back to relays when NAT gets in the way.
  • Hosted tunnels such as Cloudflare Tunnel, which publish a web service without opening any inbound port.
  • IPv6, where many providers give each device a public address and no NAT is involved, though the router’s firewall still needs a rule to allow the traffic.
  • Asking the provider for a public IPv4 address. Some offer it free on request, some charge, some refuse.
Window

Making a port forward work when it can

Checklist for a public address

When the router’s WAN address matches the public one, failures usually come down to a short list:

  1. The forward points to the right internal address, and that address is reserved in DHCP so it does not change.
  2. The service listens on all interfaces (0.0.0.0), not just on 127.0.0.1, as the lab’s web server did.
  3. The device’s own firewall allows the port.
  4. The test comes from outside. Many routers do not support “hairpin” NAT, so testing the public address from inside the same network can fail even when the forward works.
  5. The provider does not block the port. Some residential plans block common server ports such as 25 and 80.
  6. The public address has not changed. Most residential addresses are dynamic, so a forward that worked last month can appear broken simply because friends are still typing the old number. A dynamic DNS service, which updates a hostname whenever the address changes, solves that, and many routers have a client for one built in.

Exposure

The lab made one more point without trying to. The DNAT rule on the router matched only TCP port 8080 arriving on its WAN interface. Every other port stayed closed by default, because NAT only lets in what it has a table entry or a rule for. That default is a large part of why home networks survive as well as they do, and every forward punches a deliberate hole in it.

A port forward publishes a service to the entire internet, including automated scanners that probe every address constantly. Anything forwarded should be patched, authenticated and, ideally, limited to the one port it needs. The tunnel approaches above have the side benefit of not opening any inbound port at home at all.

Two layers of translation, one rule on the wrong layer. The home router did everything asked of it; the packet simply knocked on a door one building over.

Sources

  • RFC 1918, Address Allocation for Private Internets: https://www.rfc-editor.org/rfc/rfc1918.html
  • RFC 6598, IANA-Reserved IPv4 Prefix for Shared Address Space: https://www.rfc-editor.org/rfc/rfc6598.html

719 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *