Skip to content
Tech Interview Prep
Technical interview guide

VPNs & Tunneling

Encapsulating traffic inside another protocol to create a private, often encrypted path across an untrusted network.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: Current IETF IPsec/IKEv2/NAT-T/GRE/L3VPN/VXLAN/PMTUD/UDP, NIST IPsec, WireGuard, OpenVPN 2.6, and TLS 1.3 references reviewed 2026-09-04.

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

ESP overhead=54 bytes (AES-GCM, plus 0 to 3 bytes padding)\text{ESP overhead} = 54 \text{ bytes (AES-GCM, plus 0 to 3 bytes padding)} Tunnel MTU=1500−62=1438 with NAT-T\text{Tunnel MTU} = 1500 - 62 = 1438 \text{ with NAT-T} MSS=1438−20−20=1398\text{MSS} = 1438 - 20 - 20 = 1398

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.

Inner packet from LAN SPD match on selectors ESP encrypt and new outer IP header Underlay transit, only gateway addresses visible Peer finds SA by SPI and verifies ICV Decrypt and SPD check on inner packet Route to LAN host

When to use and when not to

SituationChooseWhy
Site-to-site, many subnets, dynamic routingRoute-based IPsec (VTI)Routing owns the decision; adding a subnet is a route change
Few fixed subnets, no routing protocolPolicy-based IPsecSimple selector pairs, but every subnet is a new selector
Need multicast or routing over a tunnel without cryptoGREReachability only; layer IPsec on top if confidentiality is needed
Host-to-host, payload protectionIPsec transport modeKeeps the original IP header
Roaming users, identity and postureRemote-access VPN with EAPIKEv2 EAP authenticates users against AAA
Overlapping tenant prefixesVRF or NATOne 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.