IPSec & VPN Deep Dive
IPSec transport vs tunnel mode, IKEv1 vs IKEv2, ESP vs AH, AWS Site-to-Site VPN, and debugging phase 1/2 failures.
Overview
Overview IPSec (Internet Protocol Security) is a suite of protocols for authenticating and encrypting IP traffic. It operates at Layer 3, making it transport-agnostic — any TCP/UDP/ICMP traffic is protected transparently.
IPSec modes: - Transport mode: encrypts only the IP payload (TCP/UDP segment). Original IP header is preserved. Used for host-to-host or host-to-gateway communication. - Tunnel mode: encrypts the entire original IP packet and wraps it in a new IP header. Used for site-to-site VPNs — the original packet is hidden inside the tunnel. The new outer IP header routes between VPN gateways.
IPSec protocols: - ESP (Encapsulating Security Payload): provides confidentiality (encryption), integrity, and optional authentication. The standard choice for VPNs. - AH (Authentication Header): provides integrity and authentication but no encryption. Rarely used alone; incompatible with NAT (AH covers the outer IP header, which NAT modifies).
IKE (Internet Key Exchange): negotiates and manages IPSec SAs (Security Associations). - IKEv1: two phases. Phase 1: establishes IKE SA (authenticated channel). Phase 2: negotiates IPSec SA (encryption parameters for data). Main mode (6 messages) or aggressive mode (3 messages, less secure). - IKEv2: single exchange, faster, more reliable NAT traversal, built-in EAP support, dead peer detection. Preferred for all new deployments.
AWS Site-to-Site VPN: managed IPSec VPN. Creates two tunnels (active/standby) between a Virtual Private Gateway (VGW) or Transit Gateway and the customer gateway (on-premises device). Uses IKEv2 by default (IKEv1 available). Pre-shared keys or certificates. BGP optional for dynamic routing.
Key concepts
- Security Association (SA)
- IKE Phase 1
- IKE Phase 2
- NAT-T (NAT Traversal)
- PFS (Perfect Forward Secrecy)
Interview questions
- What is the difference between IPSec transport mode and tunnel mode?
- How do you debug a failing AWS Site-to-Site VPN tunnel?
Sign up free to read the full topic
More Networking topics
Start free on Cariara · Coding problems · System design studio