IPsec (IP Security) AH (Authentication Header) / ESP (Encapsulating Security Payload)
What it is for
An IP packet on the public internet is plaintext: anyone on the path can read and modify it.
★★★ IPsec adds encryption and integrity at the IP layer, in two forms:
· ESP: encryption plus authentication (almost always the choice);
· AH: authentication only, no encryption (rarely used now; see the third section).
Tunnel mode vs transport mode
★★★ Tunnel mode encrypts the entire original IP packet including its header and wraps a new IP header around it. ★ So the real source and destination are hidden -- site-to-site VPNs use this.
★★★ Transport mode encrypts only the payload, keeping the original IP header. ★ Less overhead, but the endpoints are exposed -- used host to host.
★★ In one line: tunnel mode hides who is talking, transport mode does not.
★ Common misconceptions
★★★ "AH and ESP are much the same" -- AH covers the whole packet including the IP header, and NAT rewrites exactly that header -> AH cannot cross NAT. Which is why ESP is essentially the only choice today.
★★★ "IPsec just makes things a bit slower" -- it costs 50-60 bytes, and without raising the MTU you get "small packets fine, large ones stalled" -- the commonest VPN fault.
★★ "IPsec defeats traffic analysis" -- tunnel mode hides the inner addresses, but the two gateway addresses on the outside are plaintext, so who tunnels to whom is visible.