Overview
Curated: · Written: · Reviewed:
VPNs & Tunneling
In one line
A VPN wraps packets in an outer header so they cross an untrusted network. Reach for IPsec tunnel mode (ESP) when two gateways must encrypt, authenticate and carry whole subnets. Use GRE or VXLAN alone only for reachability, because they give no confidentiality or peer authentication.
Key definitions
- Underlay / overlay: the network that carries the tunnel, and the virtual network the tunnel creates.
- IKE SA (Phase 1): an authenticated, encrypted control channel between peers. No user traffic flows through it.
- Child SA (Phase 2): unidirectional ESP data SAs negotiated inside the IKE SA, bound to traffic selectors.
- SPD / SAD: the policy database says what must be protected; the SA database holds the keys and state for each SPI.
- NAT-T: ESP re-encapsulated in UDP 4500 once NAT is detected during IKE (RFC 3948).
Formulas and complexity
How it works
IKE authenticates the peers and derives keys. Child SAs are negotiated against selectors and installed as one SA per direction. Outbound, a packet matching the SPD is encrypted and wrapped in a new outer header. Inbound, the SA is found by SPI, the integrity check passes, and the inner packet must still match an SPD entry or it is dropped.
When to use and when not to
| Situation | Choose | Why |
|---|---|---|
| Site-to-site, many subnets, dynamic routing | Route-based IPsec (VTI) | Routing owns the decision; adding a subnet is a route change |
| Few fixed subnets, no routing protocol | Policy-based IPsec | Simple selector pairs, but every subnet is a new selector |
| Need multicast or routing over a tunnel without crypto | GRE | Reachability only; layer IPsec on top if confidentiality is needed |
| Host-to-host, payload protection | IPsec transport mode | Keeps the original IP header |
| Roaming users, identity and posture | Remote-access VPN with EAP | IKEv2 EAP authenticates users against AAA |
| Overlapping tenant prefixes | VRF or NAT | One routing table cannot hold two 10.0.0.0/16 routes |
Traps interviewers probe
- Treating GRE as secure. Fix: GRE gives reachability only. Anyone on the path reads and modifies inner packets. Add IPsec or MACsec.
- Assuming an up SA means the path is protected. Fix: a route pointing a more specific prefix at the WAN bypasses the VTI. Check the routing table and the SPD selectors for each destination.
- Blaming the tunnel for size-dependent hangs. Fix: compute the overhead (62 bytes with NAT-T), set the tunnel MTU and clamp MSS, and keep PMTUD working by allowing ICMP type 3 code 4.
- Claiming PFS without knowing where the ephemeral DH runs. Fix: fresh DH at each Child SA creation. Key-transport RSA, where a session key is encrypted under the long-term key, gives no forward secrecy.
- Calling a rekey safe because it succeeded. Fix: the responder keeps the old inbound SA until in-flight packets drain. Deleting it at once drops them.
Interview tips
Open with the three guarantees and state which one the design provides: reachability, confidentiality, or integrity and peer authentication.
Expect these follow-ups: why AH breaks under NAT (the authenticated outer header changes); why route-based scales better; what happens with overlapping prefixes; how a rekey is kept loss-free; why DPD says the peer is alive while traffic is blackholed (DPD tests the IKE peer, not the route or selectors).
30-second outline: "IKE authenticates the gateways and produces an encrypted control channel. Child SAs carry ESP for selectors the SPD allows, in tunnel mode so hosts never see the tunnel. Outbound I match the SPD, encrypt, and add an outer header. Inbound I find the SA by SPI, verify the ICV, then re-check the inner packet against the SPD. Overhead is 54 bytes, plus 8 for NAT-T, so I set the tunnel MTU to 1438 and clamp MSS to 1398."
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.