IP & routingIntermediate

NAT

“How does NAT let a hundred devices share one public IP? What does the NAT device keep, and what breaks because of it?”

What this tests

  • The translation table and what keys it
  • Why ports are the mechanism, not just addresses
  • Consequences: inbound connections, timeouts, exhaustion, protocol breakage

Answers by level

Read the beginner answer first and notice what is missing.

When 192.168.1.42:51000 opens a connection to 203.0.113.5:443, the NAT device rewrites the source to its public 198.51.100.1 and a chosen port, say 40001, and records a translation entry: (192.168.1.42, 51000, 203.0.113.5, 443) ↔ (198.51.100.1, 40001). Return packets to 198.51.100.1:40001 are matched against the table and rewritten back. Ports are what make sharing possible: one public address has ~64k ports, so it can multiplex tens of thousands of simultaneous flows from many private hosts. The IPv4 checksum and TCP/UDP checksums are recomputed on every rewrite.

Entries are created by outbound traffic and expire by timeout — a few minutes for idle TCP on many devices, tens of seconds for UDP. That produces the classic failures. Inbound connections have no entry, so unsolicited packets are dropped unless a static mapping (port forwarding) exists; peer-to-peer and WebRTC need STUN/TURN and hole-punching to work around it. Idle connections whose entry expires die silently: the next packet matches nothing, and the client sees a reset or a hang — the reason long-lived connections need keep-alives shorter than the NAT timeout.

Table exhaustion under high connection churn (many short-lived connections, each holding an entry through TIME_WAIT) drops new flows with a timeout to perfectly healthy destinations. And protocols that embed IP addresses in their payload (classic FTP, SIP) break unless the NAT understands them, because the address in the payload is not rewritten.

Green flags · Red flags

Strong green flag · Connects connection churn (no keep-alive) to NAT table exhaustion and explains the resulting timeouts to healthy destinations.
Green flags
  • Describes the translation entry with the port as the key
  • Knows entries are created outbound and expire by timeout
  • Names at least two breakages: inbound, idle expiry, exhaustion, embedded addresses
  • Mentions conntrack or a cloud NAT gateway’s port limits
  • Knows IPv6 makes NAT unnecessary and that dual-stack behaves differently per family
Red flags
  • Thinks NAT maps one private IP to one public IP without ports
  • Believes NAT is a security feature by design
  • Cannot explain why inbound connections fail
  • Unaware that NAT state has a timeout

Follow-up questions

F1
A WebSocket through a corporate NAT dies after ten minutes of silence. Why, and what is the fix?
F2
What is in a NAT table entry?
F3
How many concurrent connections to one destination IP:port can a single-IP NAT gateway support?

Scenario

Every service in a cluster intermittently times out on outbound HTTPS at peak, and dmesg on the nodes says nf_conntrack: table full. Explain the mechanism, the short-term mitigation and the real fix.

Learn this topic