← Interview Prep

NAT — Theory

Network Address Translation end to end: static/dynamic NAT and PAT/NAPT, SNAT vs DNAT, Cisco inside/outside terminology, how PAT rewrites and tracks flows, checksum recompute, what breaks (ALGs, IPsec NAT-T, hairpinning), NAT behavior types & traversal (STUN/TURN/ICE), CGNAT and NAT64.

NAT rewrites addresses (and usually ports) as packets cross a boundary — the workaround that let a shrinking IPv4 space serve billions of hosts. It's simple in the common case and full of edge cases interviewers love: what breaks end-to-end, why some protocols need help, and how peers behind NAT ever talk to each other.

The one that matters is PAT / NAPT (a.k.a. "NAT overload"): many private hosts share one public IP by multiplexing on source port. The router keeps a translation table and reverses the rewrite on the return packet.

Flavors

TypeWhat it does
Static NATFixed 1:1 mapping (one private ↔ one public). Used to publish a server.
Dynamic NATMany private → a pool of public, first-come; still 1:1 while active.
PAT / NAPT (overload)Many private → one public, disambiguated by port. The home/office default.
SNAT vs DNATRewrite the source (outbound, hide clients) vs the destination (inbound, port-forward / load-balance).

Cisco's four-address vocabulary: inside local (real private), inside global (the public it's translated to), outside global (real Internet host), outside local (how the outside appears inside) — "inside/outside" = whose host, "local/global" = which side of the NAT you're looking from.

How PAT works

  1. Outbound packet 10.0.0.5:51000 → 93.184.216.34:443 hits the NAT.
  2. NAT rewrites the source to 203.0.113.1:62000, stores the mapping (10.0.0.5:51000) ↔ (203.0.113.1:62000) keyed by the 5-tuple, and forwards.
  3. The reply to 203.0.113.1:62000 is matched in the table and rewritten back to 10.0.0.5:51000.

What NAT breaks (and ALGs)

NAT types & traversal (P2P)

For peer-to-peer (VoIP, gaming, WebRTC) the NAT's behavior decides whether hole-punching works:

BehaviorReturn traffic allowed from…
Full-coneAny external host, once a mapping exists (easiest to traverse).
Restricted-coneOnly IPs the inside host already sent to.
Port-restrictedOnly the same IP+port the inside host sent to.
SymmetricA new mapping per destination — hardest; often needs a relay.

STUN discovers your public mapping, TURN relays when direct fails, and ICE tries candidates in order — the WebRTC stack.

Carrier-grade & IPv6

Likely interview questions

Related: Protocol Headers · IPv6 (NAT64) · Life of a Packet.