Course contentsShow
← Security
Lesson 482 of 3,05211. Network Security - VPNs and TunnelingFree lesson

NAT Traversal (NAT-T) in IPsec

How NAT-T encapsulates ESP in UDP to allow IPsec to work through NAT devices.

NAT Traversal (NAT-T) in IPsec

What You'll Learn

You'll understand how NAT-T solves the problem of IPsec traffic breaking when passing through NAT devices by encapsulating ESP packets in UDP.

The NAT Problem for IPsec

IPsec was designed assuming end-to-end connectivity with public IP addresses. But Network Address Translation (NAT) breaks IPsec in two ways:

  1. ESP header alteration: NAT devices modify IP headers (addresses and checksums). ESP's integrity checks detect this as tampering and drop packets.
  2. No transport-layer ports: ESP is IP protocol 50—it has no TCP/UDP port numbers for NAT to use for mapping multiple internal hosts.

Think of it like trying to mail a tamper-evident envelope through a postal system that rewrites addresses on sealed packages. The recipient's tamper seal check fails every time.

How NAT-T Fixes This

NAT Traversal (NAT-T) wraps ESP packets inside UDP datagrams, typically using UDP port 4500. This gives NAT devices the port numbers they need, while keeping the ESP payload protected inside.

The process:

  1. During IKE negotiation, endpoints detect NAT presence by comparing internal/external IP addresses
  2. If NAT is detected, both sides switch from ESP (protocol 50) to UDP encapsulation
  3. ESP packets get wrapped: IP header | UDP header (port 4500) | ESP packet
  4. NAT treats it like any UDP traffic, translating addresses and ports
  5. The receiving endpoint strips the UDP wrapper and processes ESP normally

It's like putting your tamper-evident envelope inside a regular envelope that the postal system can handle—the outer wrapper gets rewritten, but the inner protected content remains intact.

Automatic Detection

Modern IPsec implementations automatically detect NAT and enable NAT-T without manual configuration, making IPsec viable for remote workers behind home routers.

Key Takeaway: NAT-T encapsulates ESP inside UDP port 4500 to allow IPsec traffic to traverse NAT devices, solving both the port-mapping and integrity-check problems that would otherwise break IPsec connections.