Bookmarks

NAT — network address translation

A method in which a device at the network edge rewrites IP addresses (and usually ports) in passing packets, so that hosts with private addresses can reach an external network.

Also: NAPT, PAT, port address translation, masquerading, CGNAT

checked 9 Nov

All terms

Private addresses such as 192.168.1.10 are valid only inside their own network and are not routed on the internet. At the boundary between the network and the internet, a translator replaces them with a single public address, so packets leaving for the outside carry a shared source address and replies return to whoever asked.

How it works

When an internal host opens a connection, the NAT device remembers the pair “host address and port” and substitutes its own public address and a free port. The translation entry is created by the outgoing connection, so nobody outside can connect first to a host behind NAT. For a server inside the network, you configure port forwarding, a permanent rule such as 203.0.113.7:443 → 192.168.1.20:443.

StageSourceDestination
request before NAT192.168.1.10:51000203.0.113.80:443
request after NAT198.51.100.7:40001203.0.113.80:443
reply before NAT203.0.113.80:443198.51.100.7:40001
reply after NAT203.0.113.80:443192.168.1.10:51000

Types

  • static NAT: a permanent one-to-one mapping between a private and a public address, for example for a server that is reached from outside;
  • dynamic NAT: private addresses take turns using addresses from a public pool;
  • NAPT (PAT): both the address and the port are rewritten, so thousands of connections can share one public address; this variant is what home routers use, and masquerade on Linux is also called masquerading;
  • CGNAT: carrier-grade NAT, in which many subscribers share a public IPv4 address, which is how providers cope with exhausted address space;
  • Twice NAT: the translator rewrites both the source and destination addresses, used when the address ranges of two networks overlap.

What it affects

Translation entries live for minutes (under RFC 4787, a UDP entry timer must not expire in less than two minutes), and a connection that sits idle for longer is dropped. Inbound connections are impossible without port forwarding, so an IPv4 address behind NAT is not treated as a permanent identifier. The behaviour of a translator for UDP and TCP is described by RFC 4787 and RFC 5382: for example, a single external “address and port” pair is kept for all destinations (Endpoint-Independent Mapping), which video calls, games and STUN depend on. IPv6 is regarded as the full replacement for NAT: every host gets a public address, and translation is no longer needed.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • firewall

    A firewall filters packets by rules and protects the network; NAT rewrites addresses and ports and does not filter.

  • reverse proxy

    A reverse proxy handles HTTP requests at the application level, whereas NAT rewrites addresses in packets without reading their contents.

In depth in the references

where the topic is covered in detail