The Internet Layer, chapter 12 of 36
NAT, CGNAT, and the Middlebox Internet
RFC 1631 proposed NAT in May 1994 as a short-term measure and doubted it even for that, and our SYN still needs it.
Our SYN leaves the laptop from 192.168.1.23, a private address that no router on the Internet will carry back. One hop later, at the home router, eleven of its sixty IPv4 bytes have changed. The server will see 198.51.100.77:40001 and never learn the address the laptop used.
- 11 of 60
- bytes of the SYN's IPv4 packet that differ on the two sides of the home router
- 22 of 23
- home gateways tested in 2025 that kept the source port, where ours picked
40001 - 150 TB
- per month of per-connection CGN logs for a million subscribers
The home router's translation table
Our SYN creates a mapping. Send packets out from the laptop and in from outside, switch the mapping and filtering behavior of RFC 4787, and see which packets get in and what the router rewrites.
How does a NAT fix a checksum without reading the payload?
The IPv4 header checksum covers the header, and the TCP checksum covers a pseudo-header with both addresses (RFC 9293, Section 3.1). A new source address breaks both checksums, and a new port breaks the TCP sum again. Recomputing it would mean reading every payload byte. Because the one's complement sum is commutative, a translator subtracts each old 16-bit word and adds the new one: HC' = ~(~HC + ~m + m') (RFC 1624, Section 3).
Three words change in each header of our SYN. The TTL shares a word with the protocol number, so the decrement is one more term. Linux does the same in csum_replace2() [Linux2026].
Who thought rewriting addresses was a good idea?
Paul Tsuchiya of Bellcore and Tony Eng of MIT, in January 1993. Their paper put a Network Address Translator at the border of each stub domain, and its abstract admitted that "FTP will fail in some but not all cases" [Tsuchiya1993].
RFC 1631 turned the paper into an Informational RFC in May 1994, written by Kjeld Borch Egevang and Paul Francis, as Tsuchiya now called himself. Its conclusion doubts the whole idea: NAT has negative characteristics that "may make it inappropriate even as a short term solution" (RFC 1631, Section 4).
Which mapping does a NAT reuse, and whom does it let in?
An endpoint-independent mapping reuses the external endpoint for every destination. An address-dependent mapping reuses it only for the same remote address, and an address-and-port-dependent mapping only for the same address and port (RFC 4787, Section 4.1). REQ-1 of RFC 5382 requires the first for TCP, because without it the address a host learns from a server outside is useless to any other peer.
Filtering is a separate decision (RFC 4787, Section 5). RFC 5382, Section 4.3 adds connection-dependent filtering, which admits no inbound connection at all. The filtering of Linux NAT is address-and-port-dependent [Linux2026].
Why did FTP hurt so much?
Because FTP writes addresses into its payload. Behind our router, an active-mode PORT command would carry 192,168,1,23, which is twelve characters, and the router would have to write 198,51,100,77, which is thirteen. The segment grows by one octet, so every later sequence number in that direction is off by one and every acknowledgment in the other direction must be shifted back (RFC 3027, Section 4.1).
Linux still has an Application Level Gateway for FTP: nf_conntrack_seqadj.c keeps the offsets. If a segment ends in the middle of a command that the FTP helper recognizes, the helper drops the segment [Linux2026].
What changes when the ISP runs the NAT too?
An ISP short of IPv4 addresses gives the home router a private address and translates a second time in its own network. RFC 6888, Section 2 notes that "carrier-grade" has nothing to do with the quality of the NAT. In April 2012, RFC 6598 reserved 100.64.0.0/10 for the link between home router and CGN, under an IESG note that records "very rough consensus".
One address offers 64,512 ports above 1023 per transport protocol. In 2016 some operators handed out as few as 512 ports per subscriber, and one web page can open many dozens of connections [Richter2016].
How do two hosts behind NATs reach each other at all?
Each asks a server outside what its address looks like and publishes the answer. Both peers then send to each other's reflexive address at about the same time, and each outbound packet opens its own NAT's filter for the other side. In the tests that RFC 5128, Section 4 summarizes, UDP hole punching worked on more than 80 percent of devices.
An address-and-port-dependent mapping defeats the trick, because the port the STUN server saw is not the port used toward the peer. Richter and colleagues found this "symmetric" behavior in 40 percent of cellular CGN networks in 2016 [Richter2016].
The book keeps asking
This chapter has 5,754 words and 12 questions. These 6 are answered only in the book and the audiobook.
- What did the home router change?
- How long does a NAT remember a flow?
- Can two hosts behind the same NAT reach each other through it?
- Who was behind 198.51.100.77 at that moment?
- Can an application simply ask the NAT for a port?
- Is a NAT a firewall, and what else sits on the path?
Open the sources
- RFC 3022 Traditional IP Network Address Translator (Traditional NAT)
- RFC 4787 Network Address Translation (NAT) Behavioral Requirements for Unicast UDP
- RFC 5382 NAT Behavioral Requirements for TCP
- RFC 7857 Updates to Network Address Translation (NAT) Behavioral Requirements
- RFC 6888 Common Requirements for Carrier-Grade NATs (CGNs)
- RFC 8445 Interactive Connectivity Establishment (ICE): A Protocol for Network Address Translator (NAT) Traversal
- RFC 3234 Middleboxes: Taxonomy and Issues
- [Linux2026] Linux kernel source tree, v7.4-rc1 (commit 6628e7d4c6b2, 1 November 2026)
All 47 documents this chapter cites, each with a link to its publisher and a copy kept here.
