Network Address Translation: NAPT, Mapping and Filtering Behavior, Hairpinning and Carrier-Grade NAT
How NAT lets many hosts share one public IPv4 address: basic NAT and NAPT, the NAT table, mapping and filtering behaviors measured in a real lab, timeouts, port forwarding, hairpinning, ALGs, NAT with ICMP and tunnels, NPTv6, and carrier-grade NAT.
kvi5hnuCode Sprout team member24 min readOn this page
By the early 1990s it was clear that IPv4's 4.3 billion addresses would run out. IPv6 was the long-term fix, but something was needed sooner. Network Address Translation (NAT) was the stopgap that became permanent: a router rewrites addresses in packets as they pass, so a whole network of hosts can use addresses that aren't globally unique and share a few public ones, often just one.
Today almost every home network and many enterprise and mobile networks sit behind NAT, and many ISPs (internet service providers) add a second layer of it. This article explains how NAT works, using a real Linux NAT in the course lab, and why it causes so much trouble for applications. Article 34 covered the firewall side, article 36 covers getting traffic through NATs, and article 37 shows how to configure NAT with nftables.
The basic idea
A NAT sits on the boundary between an inside address realm and the outside (usually the Internet). Inside hosts use private addresses from the ranges reserved in RFC 1918: 192.168.0.0/16, 172.16.0.0/12 and 10.0.0.0/8. Anyone may use these, and many networks use the same ones, so Internet routers don't route them.
You can see that in the lab. The inside network is 10.0.0.0/24, the NAT's outside address is 203.0.113.1, and the server is 198.51.100.10, two routers away. With translation turned off, an inside host can't connect at all:
hostA: connect from port 40000 failed: timed out
The SYN (the first packet of a TCP connection, article 34) did reach the server, but the server's reply was addressed to 10.0.0.10, and the ISP's router had no route for a private address, so it dropped the reply.
When outgoing packets pass through the NAT, it rewrites their source address to its own public address. When replies come back, it rewrites the destination address back to the inside host's. The NAT must remember which inside host each flow belongs to, so it keeps a table of active mappings, also called sessions or bindings. That table is the same connection-tracking state a stateful firewall keeps, and on Linux it's literally the same conntrack table.
Rewriting an address isn't free. The IPv4 header checksum covers the addresses, and so do the TCP and UDP checksums (through a "pseudo-header", explained in article 45), so a NAT must update those checksums on every packet it changes.
Basic NAT and NAPT
There are two forms of what's called traditional NAT (RFC 3022):
- Basic NAT rewrites only addresses, mapping each inside address to one address from a pool of public addresses. It needs as many public addresses as there are inside hosts talking at the same time, so it saves few addresses and is rare today.
- Network Address Port Translation (NAPT) also rewrites port numbers (and ICMP query identifiers). Thousands of inside hosts can share one public address, because each flow gets a different public port. When people say "NAT" today, they almost always mean NAPT. Linux calls it masquerading.
Here are two inside hosts in the lab, hostA (10.0.0.10) and hostB (10.0.0.11), each connecting from port 40000 to the same server. Then hostA connects again from port 40001. Each line shows the address and port the server reported seeing:
hostA: local 10.0.0.10:40000 -> you are 203.0.113.1:40000
hostB: local 10.0.0.11:40000 -> you are 203.0.113.1:24198
hostA: local 10.0.0.10:40001 -> you are 203.0.113.1:40001
The server's log agrees:
server: connection from 203.0.113.1:40000
server: connection from 203.0.113.1:24198
server: connection from 203.0.113.1:40001
And here is the NAT's table afterward, one entry per connection, in the conntrack format from article 34. The diagram after it draws the same two hosts and their translations:
tcp 6 119 TIME_WAIT src=10.0.0.11 dst=198.51.100.10 sport=40000 dport=80 src=198.51.100.10 dst=203.0.113.1 sport=80 dport=24198 [ASSURED]
tcp 6 119 TIME_WAIT src=10.0.0.10 dst=198.51.100.10 sport=40000 dport=80 src=198.51.100.10 dst=203.0.113.1 sport=80 dport=40000 [ASSURED]
tcp 6 119 TIME_WAIT src=10.0.0.10 dst=198.51.100.10 sport=40001 dport=80 src=198.51.100.10 dst=203.0.113.1 sport=80 dport=40001 [ASSURED]

Three things to notice:
- Port preservation. hostA's first connection kept its source port, 40000. A NAT tries to keep the inside port when it's free, which helps some applications.
- Port collision. hostB also used port 40000, but
203.0.113.1:40000to the same server was already taken, so the NAT picked another port. Two flows must never look identical on the outside, or replies couldn't be told apart. - The reply tuple tells the story. In each conntrack entry, the second half shows the packets the NAT expects back: from the server to
203.0.113.1and the public port. When one arrives, the NAT looks it up and rewrites it to the inside address and port in the first half.
NAT state for TCP, UDP and ICMP
The NAT must decide when a mapping is no longer needed. The IETF's BEHAVE working group wrote requirements for this, after years in which every vendor did something different:
- TCP (RFC 5382). The NAT can follow the connection: a SYN creates the mapping, and FIN or RST (TCP's close and reset packets) end it. An established connection may be idle for a very long time, since TCP sends nothing when there's nothing to say and keepalives (article 71) default to every 2 hours. So the NAT must keep an idle established mapping for at least 2 hours and 4 minutes, and a half-open or half-closed one for at least 4 minutes. A NAT must also handle the rare simultaneous open, where both ends send a SYN at once, which peer-to-peer applications use.
- UDP (RFC 4787). There's no start or end, only traffic. A mapping is created by the first outgoing datagram and removed after an idle timeout, which must be at least 2 minutes (5 minutes is recommended), except for specific services such as DNS. The timer must be refreshed by outgoing traffic, and may also be refreshed by incoming traffic.
- ICMP (RFC 5508). Echo requests and replies are tracked by their query identifier, the way ports are used for TCP and UDP, with a timeout of at least 60 seconds. ICMP errors are harder: an error such as "port unreachable" carries a copy of the header of the packet that caused it, so the NAT must also rewrite the addresses and ports inside that embedded copy, or the inside host won't be able to match the error to its connection.
Real NATs often fall short of these minimums. Here is a measurement of the lab's Linux NAT: an inside host sends one UDP datagram, and the server answers after a delay. Replies that arrive while the mapping exists get through, and later ones don't. The second output is the kernel setting behind the result, and the chart plots the replies against it:
reply after 5 s idle: delivered
reply after 10 s idle: delivered
reply after 15 s idle: delivered
reply after 20 s idle: delivered
reply after 25 s idle: delivered
reply after 28 s idle: delivered
reply after 32 s idle: dropped by the NAT (mapping expired)
reply after 35 s idle: dropped by the NAT (mapping expired)
reply after 40 s idle: dropped by the NAT (mapping expired)
reply after 45 s idle: dropped by the NAT (mapping expired)
reply after 50 s idle: dropped by the NAT (mapping expired)
net.netfilter.nf_conntrack_udp_timeout = 30

The Linux default for a UDP flow that has seen only one direction is 30 seconds. Once replies have flowed, it becomes 120 seconds (nf_conntrack_udp_timeout_stream). Both are shorter than the 2 minutes RFC 4787 requires for the one-way case, and many home routers use timeouts as short as 30 to 60 seconds. That's why applications that rely on UDP mappings, such as VoIP (voice over IP), games and VPNs (virtual private networks), send keepalive packets every 15 to 25 seconds.
Fragments, other transports, tunnels and multicast
- Fragments. Only the first fragment of a fragmented datagram carries the TCP or UDP header (article 46). A NAPT therefore can't translate later fragments on their own. RFC 4787 requires NATs to handle fragments, which in practice means reassembling them, or at least holding later fragments until the first one arrives. Many cheap NATs simply drop fragments.
- Other transports. NAT behavior has also been specified for DCCP (the Datagram Congestion Control Protocol, RFC 5597), and an IETF draft for SCTP (a message-based transport, article 87) stalled without becoming an RFC. Most consumer NATs don't support either, which is one reason new transports are now built on UDP (QUIC is the main example, in article 86).
- Tunnels. A NAT must understand what it's translating. GRE as used by the old PPTP VPN (article 20) has a Call ID that must be mapped like a port. IPsec's ESP (its encrypted payload, article 82) has no ports at all, so IPsec through NAT wraps ESP in UDP port 4500 (NAT traversal, article 82).
- Multicast. A NAT can forward multicast by acting as an IGMP proxy (IGMP is how hosts join multicast groups, article 44; RFC 5135), but it's rarely configured.
Mapping and filtering behavior
Applications that need to be reached from outside, such as voice and video calls or peer-to-peer games, care exactly how a NAT reuses mappings and which incoming packets it lets through. RFC 4787 defines the vocabulary, and it replaced older, vaguer terms such as "full cone" and "symmetric NAT". There are two independent questions:

Mapping behavior: does an inside socket keep the same public address and port for different destinations?
- Endpoint-independent mapping (EIM): yes, for every destination. RFC 4787 requires this, because it's what lets a peer-to-peer application learn its public address from one server and give it to others (article 36).
- Address-dependent mapping: a new mapping for each destination address.
- Address and port dependent mapping: a new mapping for each destination address and port. This is the old "symmetric NAT", and it defeats most traversal techniques.
The lab NAT reused the same mapping. One inside socket (10.0.0.10 port 5000) sent to three different destinations, and each one reported what it saw:
10.0.0.10:5000 -> 198.51.100.10:3478 saw you as 203.0.113.1:5000
10.0.0.10:5000 -> 198.51.100.10:3479 saw you as 203.0.113.1:5000
10.0.0.10:5000 -> 198.51.100.11:3478 saw you as 203.0.113.1:5000
All three saw 203.0.113.1:5000. That's endpoint-independent mapping, with the port preserved too.
Filtering behavior: once a mapping exists, which outside hosts may send to it?
- Endpoint-independent filtering: anyone. Recommended when transparency for applications matters most.
- Address-dependent filtering: only addresses the inside host has sent to. Recommended when stricter filtering matters more.
- Address and port dependent filtering: only the exact address and port the inside host has sent to.
To test the lab NAT, a fresh inside socket (port 6000) sent one datagram to 198.51.100.10:3478. Then the server sent an unsolicited datagram to the mapping (203.0.113.1:6000) from three different places:
server sent from 198.51.100.11:3478 to 203.0.113.1:6000
server sent from 198.51.100.10:3479 to 203.0.113.1:6000
server sent from 198.51.100.10:3478 to 203.0.113.1:6000
What the inside host received:
hostA sent one datagram 10.0.0.10:6000 -> 198.51.100.10:3478
hostA received 'unsolicited' from 198.51.100.10:3478
Only the datagram from the exact address and port the host had contacted got through. A different port on the same server, and a different address, were both blocked. The NAT's table shows the two rejected datagrams as separate, [UNREPLIED] flows aimed at the NAT itself. (In these lines, 17 is UDP's protocol number and 26 the seconds left before the entry expires.)
udp 17 26 src=198.51.100.10 dst=203.0.113.1 sport=3479 dport=6000 [UNREPLIED] src=203.0.113.1 dst=198.51.100.10 sport=6000 dport=3479
udp 17 26 src=198.51.100.11 dst=203.0.113.1 sport=3478 dport=6000 [UNREPLIED] src=203.0.113.1 dst=198.51.100.11 sport=6000 dport=3478
udp 17 26 src=10.0.0.10 dst=198.51.100.10 sport=6000 dport=3478 src=198.51.100.10 dst=203.0.113.1 sport=3478 dport=6000
So Linux masquerading is endpoint-independent mapping with address and port dependent filtering, the combination most home routers have too. It's friendly enough for most NAT traversal, as long as both sides send to each other at about the same time (article 36 explains why).
A few more terms from the same requirements:
- IP address pooling. A NAT with several public addresses should give the same inside host the same public address for all its flows ("paired" pooling), so that servers don't think they're talking to different hosts.
- Port overloading, giving two inside hosts the same public address and port, is forbidden: replies couldn't be told apart.
- Port parity means keeping even ports even and odd ports odd, which old RTP (Real-time Transport Protocol, for voice and video) media software relied on. It was originally recommended and later made optional (RFC 7857).
Servers behind a NAT: port forwarding
NAPT only creates mappings for flows that start inside. A server behind a NAT can't be reached from outside unless the NAT is told where to send incoming connections. That's port forwarding (destination NAT, or a static mapping): "TCP traffic arriving on public port 8080 goes to 10.0.0.20 port 80".
In the lab, the NAT forwards public port 8080 to a web server at 10.0.0.20. From the outside server:
server: curl http://203.0.113.1:8080/ -> hello from the web server at 10.0.0.20
Port forwarding has limits. There's only one public port 8080 per public address, so two inside web servers can't both use it. It needs manual setup (or a protocol for setting it up, article 36). And it fails completely behind carrier-grade NAT, where you don't control the outer NAT.
Hairpinning (NAT loopback)
What happens when hostA, inside the same network, uses the public address to reach that forwarded server? This is common: a laptop is given the server's public name, which resolves to the public address, whether it's at home or not. In the lab, with only the forwarding rule for the outside interface:
hostA: curl http://203.0.113.1:8080/ -> failed: connection refused (curl exit 7)
The NAT itself got the connection and had nothing listening on 8080, so it refused. Adding a destination NAT rule for the inside interface isn't enough on its own, though. With only that rule, hostA's connection times out, and a capture on hostA shows why:
hostA: curl http://203.0.113.1:8080/ -> failed (curl exit 28)
IP 10.0.0.10.43648 > 203.0.113.1.8080: Flags [S], seq <n>, win <w>, length 0
IP 10.0.0.20.80 > 10.0.0.10.43648: Flags [S.], seq <n>, ack <n>, win <w>, length 0
IP 10.0.0.10.43648 > 10.0.0.20.80: Flags [R], seq <n>, win <w>, length 0
IP 10.0.0.10.43648 > 203.0.113.1.8080: Flags [S], seq <n>, win <w>, length 0
The NAT changed the destination to 10.0.0.20 and passed the SYN on. But the web server saw a source of 10.0.0.10, on its own network, so it replied directly to hostA, not through the NAT. hostA received a SYN-ACK from 10.0.0.20:80 when it was expecting one from 203.0.113.1:8080, didn't recognize it, and reset it. In this tcpdump output, Flags [S] is a SYN, [S.] a SYN-ACK (the dot stands for the ACK flag), and [R] a reset. The last line is hostA retrying its SYN.
The fix is to also rewrite the source of hairpinned packets to the NAT's own inside address, so the server replies to the NAT, which can translate the reply back:

hostA: curl http://203.0.113.1:8080/ -> hello from the web server at 10.0.0.20
tcp 6 119 TIME_WAIT src=10.0.0.10 dst=203.0.113.1 sport=41536 dport=8080 src=10.0.0.20 dst=10.0.0.1 sport=80 dport=41536 [ASSURED]
The reply tuple now points at 10.0.0.1, the NAT. The web server's log shows the cost of this trick: it saw the outside client's real address, but it saw the inside client as the NAT:
198.51.100.10 - - [date] "GET / HTTP/1.1" 200 -
10.0.0.1 - - [date] "GET / HTTP/1.1" 200 -
This is hairpinning, also called NAT loopback or NAT reflection, because the packet goes into the NAT and turns straight back. RFC 4787 and RFC 5382 require NATs to support it, and many home routers do. When a router doesn't, the usual workaround is split DNS: inside clients get the server's private address from the local DNS (article 54).
The full rule set used in the lab. The prerouting chain rewrites destinations as packets arrive (the forwarding rule from outside and the hairpin rule from inside), and the postrouting chain rewrites sources as packets leave (masquerading toward the Internet, and the hairpin source NAT):
table ip nat {
chain prerouting {
type nat hook prerouting priority dstnat; policy accept;
iifname "wan" tcp dport 8080 dnat to 10.0.0.20:80
iifname "br0" ip daddr 203.0.113.1 tcp dport 8080 dnat to 10.0.0.20:80
}
chain postrouting {
type nat hook postrouting priority srcnat; policy accept;
oifname "wan" masquerade
iifname "br0" oifname "br0" ip daddr 10.0.0.20 tcp dport 80 masquerade
}
}
NAT editors and ALGs
Translating headers is enough for protocols that only use headers to identify endpoints. Some protocols also put addresses and ports inside their payload, and those break:
- FTP (the File Transfer Protocol) in active mode tells the server, in a text command such as
PORT 10,0,0,10,156,64, which address and port to connect back to: the first four numbers are the address10.0.0.10, and the last two the port, 156 × 256 + 64 = 40000. Behind a NAT, that's a private address. - SIP (the Session Initiation Protocol, for voice over IP) puts the addresses for audio and video streams in its messages.
A NAT that rewrites these payloads is called a NAT editor, or more generally an application-level gateway (ALG). It must parse the protocol, and if the rewritten text is longer or shorter, it must also adjust TCP sequence numbers for the rest of the connection. ALGs are fragile: they break when the protocol is encrypted (they can't see inside TLS), and buggy SIP ALGs in home routers are a well-known cause of one-way audio. Linux still has helpers such as nf_conntrack_ftp, but since kernel 4.7 they no longer apply automatically and must be assigned to traffic explicitly. Modern protocols avoid putting addresses in payloads, or use NAT traversal instead (article 36).
NAT and IPv6
IPv6 was designed to make NAT unnecessary, and the IETF recommends against NAPT for IPv6. Every host can have a global address, and a stateful firewall provides the "nothing comes in unless asked" protection people associate with NAT. There is an experimental NPTv6 (Network Prefix Translation, RFC 6296), which swaps one prefix for another of the same length (often a /48) without touching ports, so it's stateless and fully reversible. It's used for things like multihoming without provider-independent addresses, but it's uncommon.
Carrier-grade NAT
With IPv4 addresses exhausted, many ISPs can't give every customer a public address. Instead, they run a large NAT in their own network. This is carrier-grade NAT (CGN), also called large-scale NAT (LSN) or service-provider NAT. A customer's home router gets an address from 100.64.0.0/10, the shared address space reserved for this purpose (RFC 6598). It's not RFC 1918 space, so it can't clash with whatever the customer uses inside.
Combined with the home router's own NAT, the customer now sits behind two NATs ("NAT444": private, shared, then public addresses). The lab reproduces it, with a laptop on 192.168.1.0/24, a home router whose outside address is 100.64.0.2, and a CGN with public address 203.0.113.1. traceroute shows the path, one router per line: the home router (192.168.1.1), the CGN (100.64.0.1), an ISP router, and the server (article 41 explains traceroute):
traceroute to 198.51.100.10 (198.51.100.10), 30 hops max, 60 byte packets
1 192.168.1.1 0.190 ms
2 100.64.0.1 0.071 ms
3 203.0.113.254 0.034 ms
4 198.51.100.10 0.065 ms
What the server sees:
laptop uses 192.168.1.10:45200; server sees 203.0.113.1:45200
Each NAT keeps its own table. The home router translated 192.168.1.10 to 100.64.0.2:
tcp 6 119 TIME_WAIT src=192.168.1.10 dst=198.51.100.10 sport=45200 dport=80 src=198.51.100.10 dst=100.64.0.2 sport=80 dport=45200 [ASSURED]
And the CGN translated 100.64.0.2 to 203.0.113.1:
tcp 6 119 TIME_WAIT src=100.64.0.2 dst=198.51.100.10 sport=45200 dport=80 src=198.51.100.10 dst=203.0.113.1 sport=80 dport=45200 [ASSURED]
CGN has real downsides, and RFC 6888 sets requirements to limit them:
- No inbound connections. Customers can't run servers or use port forwarding, because they don't control the CGN.
- Shared reputation. Hundreds of customers share one public address. If one of them sends spam or attacks, the address gets blocked or flooded with CAPTCHAs for all of them.
- Port limits. Each customer gets a limited share of ports. A busy household can run out, and applications fail in confusing ways. RFC 6888 requires the CGN to limit each subscriber's ports so one can't starve the others.
- Logging. To answer legal requests, the ISP must record which customer used which public address and port at which moment, which is far more data than logging address assignments.
- Traversal is harder. The CGN must support hairpinning (RFC 6888 requires it), because two customers of the same ISP talking to each other go in and out of the same CGN. Endpoint-independent mapping is also required, so NAT traversal (article 36) still has a chance.
CGN is one of the main reasons ISPs deploy IPv6: traffic that goes over IPv6 doesn't need a CGN. Article 38 covers that transition, including DS-Lite, which puts the CGN at the end of an IPv6 tunnel.
Common questions
Does NAT make my network secure?
It blocks unsolicited inbound connections as a side effect, because there's no mapping for them, which hides inside hosts from scans. But it's not a firewall policy: port forwarding, UPnP (article 36) and malware on an inside host that connects out all bypass it. Treat NAT as address sharing and rely on a stateful firewall for security, which is what IPv6 networks do without NAT.
Why do my two devices show the same public IP address?
Because they're both behind the same NAPT. Every outgoing flow from your home gets your router's public address, and only the port differs. With carrier-grade NAT, many of your neighbors may show the same address too.
How can I tell whether I'm behind carrier-grade NAT?
Compare the "WAN" or "Internet" address your home router shows with what a "what is my IP" website reports. If the router's address is in 100.64.0.0/10 or a private range, or simply differs from what the website sees, there's another NAT between you and the Internet. A traceroute that shows a 100.64.x.x hop is another sign.
What are "full cone", "restricted cone" and "symmetric" NAT?
They're older names, from the first STUN specification (a protocol for discovering your public address, article 36), for combinations of the behaviors in this article. Full cone is endpoint-independent mapping and filtering. Restricted cone is endpoint-independent mapping with address-dependent filtering, and port-restricted cone adds port-dependent filtering. Symmetric is address and port dependent mapping. RFC 4787's two separate questions describe NATs more accurately, so prefer them.
Why does my UDP application stop receiving after a minute of silence?
The NAT's mapping timed out. Without traffic, the NAT can't tell whether the flow is still wanted, and it removes the mapping after its idle timeout, 30 seconds in the lab's Linux NAT. Later incoming datagrams then match nothing and are dropped. Send a small keepalive more often than the shortest timeout you expect to meet; 15 to 25 seconds is common.
Can a NAT run out of ports?
Yes. One public address has about 64,000 ports per protocol. Some NATs stretch that by reusing a public port for flows to different destinations, but a NAT with endpoint-independent mapping ties each public port to one inside socket, so the 64,000 is a real limit. A carrier-grade NAT shared by thousands of customers, or a cloud NAT gateway used by a busy service that makes many connections to the same API, can exhaust them. Connections then fail to start. The fixes are more public addresses, longer-lived connections that get reused, or IPv6.
Why doesn't active-mode FTP work through my NAT, when passive mode does?
In active mode, the client sends its own address and port in the FTP payload and the server connects back to it, which fails when that address is private and there's no mapping. In passive mode, the server sends its address and port and the client makes the second connection outward, which the NAT handles like any other outgoing connection.
Summary
- NAT rewrites addresses at a realm boundary so inside hosts with non-unique addresses (RFC 1918 ranges) can share public addresses. NAPT rewrites ports too, so thousands of hosts can share one address, and it updates the IP and transport checksums.
- The NAT table records each flow and its translation. The lab showed port preservation for the first flow, a new port on collision, and the reply tuple the NAT uses to route replies back.
- Mappings expire after idle timeouts. RFC 5382 requires at least 2 hours 4 minutes for idle established TCP, RFC 4787 at least 2 minutes for UDP, and RFC 5508 at least 60 seconds for ICMP queries. The lab's Linux NAT dropped a one-way UDP mapping after 30 seconds.
- Mapping behavior asks whether an inside socket keeps one public port for all destinations (endpoint-independent is required). Filtering behavior asks who may send to it. Linux, like most home routers, is endpoint-independent mapping with address and port dependent filtering.
- Port forwarding exposes inside servers. Hairpinning lets inside hosts reach them by their public address, and needs source NAT as well as destination NAT, as the lab's capture showed.
- Protocols that carry addresses in their payload need fragile ALGs. IPv6 avoids NAT, using firewalls instead, with NPTv6 as a rare stateless option.
- Carrier-grade NAT uses
100.64.0.0/10between the customer and the ISP, which means two NATs, shared addresses, port limits and no inbound connections.
Practice questions
1. A NAT with public address 203.0.113.1 has these mappings: 10.0.0.5 to 203.0.113.1, and 10.0.0.6 to 203.0.113.1. A TCP segment arrives from 198.51.100.10 to 203.0.113.1. What does the NAT do with it?
Answer
It looks up the mapping for public port 50001 (and, for a port-dependent NAT, checks that this flow was to 198.51.100.10). It rewrites the destination to 10.0.0.6, updates the IP and TCP checksums, and forwards the segment to 10.0.0.6.
2. Why does RFC 4787 require endpoint-independent mapping but leave the filtering behavior as a choice?
Answer
Endpoint-independent mapping is what makes NAT traversal possible: a host learns its public address and port from one server (such as a STUN server) and can give it to peers, knowing the NAT will use the same mapping for them. Filtering is a security trade-off. Endpoint-independent filtering is more transparent for applications, while address-dependent or address and port dependent filtering is stricter, so the RFC lets operators choose.
3. An inside client and an inside web server both use 192.168.1.0/24. The client connects to the router's public address on a forwarded port, and the connection times out. Explain what is happening on the wire and give two fixes.
Answer
The router rewrites the destination to the web server, but leaves the client's private source address. The server replies directly to the client on the local network, from its own private address and port. The client doesn't recognize the reply and resets it, so the handshake never completes. Fixes: add a source NAT (masquerade) rule for hairpinned traffic so replies go through the router, or use split DNS so inside clients resolve the server's name to its private address.
4. A game uses UDP and goes silent for 45 seconds between rounds. Players behind some home routers stop receiving updates from the server after the pause. What's the cause, and how should the game be changed?
Answer
The home router's UDP mapping expired during the silence. When the server sends again, there's no mapping, so the router drops the datagrams. The game should send a small keepalive datagram from the client more often than the shortest likely timeout, for example every 15 to 20 seconds, so the mapping is refreshed by outgoing traffic.
5. Why can't a simple NAPT translate the second fragment of a fragmented UDP datagram on its own?
Answer
Only the first fragment carries the UDP header with the port numbers. Later fragments have only the IP header and the rest of the data, so the NAT can't tell which mapping they belong to from the fragment alone. It must reassemble the datagram, or remember the IP identification value from the first fragment, before it can translate them.
6. A customer's router shows a WAN address of 100.64.12.7. Can they run a game server reachable from the Internet with port forwarding? Why or why not?
Answer
No, not with port forwarding on their own router alone. 100.64.12.7 is in the shared address space used for carrier-grade NAT, so there's another NAT at the ISP that the customer doesn't control. Incoming connections stop at the CGN, which has no mapping for them. Options are asking the ISP for a public address, using IPv6, using a tunnel or relay service, or using a protocol like PCP if the ISP's CGN supports it (article 36).
Previous: Firewalls: Packet Filters, Stateful Inspection and Proxies
Next: Getting Through NAT: Hole Punching, STUN, TURN, ICE, UPnP and PCP

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.