office Ainternetoffice B
Small white envelope: the original packet, its seal shows the senderBig envelope with a padlock: ESP tunnel mode, the teal tab is the new outer headerYellow coins on the gateways: the keys IKEv2 agreed, never sentPink block: the eavesdropper; its bubble shows what it can readTwo offices, 192.168.1.0/24 and 192.168.2.0/24, are joined across the internet. The gateways first run IKEv2 (UDP port 500): a Diffie–Hellman exchange gives both the same secret, then each proves who it is and they agree what to protect. The laptop's packet to 192.168.2.20 is wrapped whole in ESP tunnel mode at Gateway A, under a new outer header from 198.51.100.10 to 203.0.113.20, and unwrapped at Gateway B. The eavesdropper sees only the outer header; changed or replayed copies are dropped. 198.51.100.10, 203.0.113.20 and 192.0.2.50 are RFC 5737 documentation addresses; 192.168.1.0/24 and 192.168.2.0/24 are RFC 1918 private networks. SPI values are illustrative.

The attack fails

  1. An eavesdropper on the internet copies every packet between two offices. With IPsec each copy is a locked envelope: it shows the two gateway addresses, never the computers, ports or data inside. Here is how that lock is built.

IKEv2 builds the tunnel

ESP carries the packet

Other kinds of VPN

The packet, field by field

;; step 1/12 · tap-fails · preview
;; gateway a → gateway b
what the eavesdropper records:
  outer IPv4  198.51.100.10 → 203.0.113.20
  protocol    50 (ESP)
  SPI 0x3a5f1c27 · sequence 1 · 176 bytes · timing
what it cannot read or change unnoticed:
  192.168.1.10 → 192.168.2.20, TCP ports, the data

Tunnel mode with AES-GCM adds 54–57 bytes to every packet: a 20-byte outer header, 8 bytes of SPI and sequence number, an 8-byte IV, 0–3 bytes of padding, 2 trailer bytes and a 16-byte tag. If a gateway or laptop is behind NAT, IKEv2 notices and moves to UDP port 4500, carrying ESP inside UDP so the NAT can track it (RFC 3948).