DEV Community

Cover image for NAT Explained: SNAT vs DNAT, PAT & Why It Matters
Long Nguyen
Long Nguyen

Posted on

NAT Explained: SNAT vs DNAT, PAT & Why It Matters

NAT explained — a compact, beginner-friendly primer you can read in minutes.

What is NAT in a nutshell?

  • Network Address Translation (NAT) rewrites IP addresses (and sometimes ports) at a network boundary so private hosts can communicate across public networks. Connection tracking keeps translation state so return traffic finds the right internal host.

Why it exists

  • IPv4 address scarcity: NAT lets many devices share a few public IPs. It also enables common edge patterns like controlled egress, segmentation, and inbound publishing (port forwarding).

Core types (quick mental model)

  • SNAT (Source NAT): Rewrites the source IP (and often port) for outbound traffic — used for internet access from private ranges.
  • DNAT (Destination NAT): Rewrites destination IP/port for inbound traffic — used for port forwarding/publishing services.
  • PAT / Masquerade: Port Address Translation maps many private hosts to one public IP by using different source ports (common in home routers).

Where you’ll see NAT

  • Home routers (masquerade/PAT), edge firewalls, cloud gateways and Linux iptables/nftables setups. Each platform has slightly different commands and gotchas.

Limitations & troubleshooting tips

  • NAT breaks end-to-end addressing (useful for security but problematic for some apps like peer-to-peer). Watch out for protocols that embed IPs in payloads, asymmetric routing, and state table exhaustion. Use logging and connection-tracking counters when diagnosing.

Want the full walkthrough with Linux and cloud examples, common pitfalls, and step-by-step troubleshooting? Read the full guide:

Full NAT guide on Netalith

Brand: Netalith — Practical networking guides for engineers and operators.

Top comments (0)