Services

Resources

Company

NAT (network address translation)

Network address translation (NAT) is the rewriting of source or destination IP addresses, and often ports, in packets as they cross a router or gateway. Its most common use lets many hosts with private addresses, such as 10.0.0.0/8, reach the internet through one or a few public IP addresses. Replies are translated back to the right private host.

How it works

Source NAT (SNAT) rewrites the sender's address on the way out and records the mapping in a connection-tracking table. Destination NAT (DNAT) rewrites the target address on the way in, which is how port forwarding works. On Linux, iptables rules in the nat table implement both. For example, iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE lets a machine share its internet connection. Kubernetes uses similar rules to route Service traffic to pods.

Why it matters in production

Managed NAT gateways in the cloud usually charge per GB of data processed. A workload that pulls 100 TB per month from the internet can make NAT one of the largest line items on the bill. NAT also hides the original client address and can exhaust source ports under heavy connection churn.

See also

On the One2N blog

References

  1. Origin of the term

  2. RFC 3022: Traditional IP network address translator

  3. The netfilter.org project

Comic about network address translation: 3 computers with private addresses 10.0.0.1 to .3 share one public address, 203.0.113.5; NAT swaps 10.0.0.1 for the public address and notes port 61001 so replies return to it; on sale day 2,000 x 40 = 80,000 connections need more than the roughly 64,000 ports one address has, and new connections fail; a second public address gives 128,000 ports.