IPsec (IP Security) AH (Authentication Header) / ESP (Encapsulating Security Payload)
What it is for
An IP packet crosses the public internet in plaintext: any device on the path can read and modify it.
IPsec adds encryption and integrity checking at the IP layer, in two forms:
· ESP: encryption plus authentication (almost always the one used);
· AH: authentication only, no encryption (rarely used now, because it cannot traverse NAT).
Tunnel mode and transport mode
Tunnel mode encrypts the entire original IP packet, including its header, and adds a new IP header outside it. The real source and destination are not visible on the path; site-to-site VPNs use this mode.
Transport mode encrypts only the payload and keeps the original IP header. It has less overhead, but the source and destination are visible; it is used host to host.
Tunnel mode hides the addresses of the two parties; transport mode does not.
Common misconceptions
AH and ESP are not interchangeable: AH covers the whole packet including the IP header, and NAT rewrites that header, so AH cannot traverse NAT. ESP is essentially the only choice today.
IPsec overhead affects the MTU: each packet grows by 50-60 bytes, and if the MTU is not lowered accordingly, small packets get through while large ones are dropped.
IPsec does not prevent traffic analysis: tunnel mode hides the inner addresses, but the two gateway addresses on the outside are plaintext, so who has a tunnel to whom is visible.