courses

VPNs and IPSec

What a VPN actually does — and what it doesn’t

A Virtual Private Network (VPN) builds an encrypted tunnel across an untrusted network, so that traffic flowing through it gets confidentiality and integrity even though the underlying path is hostile. The classic threat model is the untrusted local network: coffee-shop Wi-Fi, a hotel LAN, an ISP that logs everything, or the public Internet between two office sites. Inside the tunnel, an eavesdropper sees only ciphertext between you and the VPN endpoint.

That is genuinely useful, but VPNs are surrounded by marketing myths, so it is worth being precise about the boundaries up front:

With the scope honest, the rest of this page is about how the tunnel is built.

Topologies

  Remote-access VPN                         Site-to-site VPN
  ┌────────┐                                ┌──────────┐            ┌──────────┐
  │ laptop │═══tunnel═══▶┌─────────┐        │ Office A  │═══tunnel══▶│ Office B  │
  └────────┘   over      │ VPN     │─▶ LAN  │ gateway   │  over the  │ gateway   │
               Internet  │ gateway │        │ (whole    │  Internet  │ (whole    │
                         └─────────┘        │  subnet)  │            │  subnet)  │

A second axis, for remote access:

IPSec: the standards-based suite

IPSec is the IETF’s protocol suite for securing traffic at the network layer (Layer 3) — it protects IP packets themselves, so it works for any application transparently. It is the backbone of most site-to-site VPNs and is built into virtually every OS and router. IPSec is a suite, not one protocol; the pieces you need to know:

AH vs ESP — the two protections

Transport vs tunnel mode — what gets wrapped

IKE — key exchange

IPSec needs both ends to agree on keys. IKEv2 (Internet Key Exchange, RFC 7296) does the authenticated key negotiation, using a Diffie–Hellman exchange to derive fresh session keys — providing Perfect Forward Secrecy so that compromising a long-term key does not expose past sessions. IKE is also where IPSec’s notorious complexity lives: many configurable cipher suites, DH groups, and modes, which is both its flexibility and a frequent source of misconfiguration.

TLS-based VPNs: OpenVPN

Not every VPN works at Layer 3. OpenVPN builds the tunnel on top of TLS (the same protocol as HTTPS), running in userspace over UDP or TCP — and, by riding TCP/443, it can traverse restrictive firewalls that block IPSec. It is mature, audited, and cross-platform, at some cost in performance versus kernel implementations. SSL/TLS VPNs are common for remote access where firewall traversal matters.

WireGuard: the modern approach

WireGuard is a newer VPN that has rapidly become a default choice, and its design philosophy is the lesson worth absorbing — it is a case study in economy of mechanism:

  IPSec (IKEv2/ESP) OpenVPN WireGuard
Layer Network (L3) TLS over UDP/TCP Network (L3, kernel)
Crypto Configurable (many options) Configurable (OpenSSL) Fixed modern suite
Codebase Very large Large ~4,000 lines
Firewall traversal Hard (ESP/NAT issues) Easy (TCP/443) Moderate (UDP)
Config complexity High Medium Low

Worked example: a minimal WireGuard tunnel

WireGuard’s simplicity shows in its configuration. Each side generates a keypair, and each lists the other’s public key plus which IPs it may use.

# 1. Generate a private + public key on each peer
$ wg genkey | tee privatekey | wg pubkey > publickey

# 2. /etc/wireguard/wg0.conf  — on the CLIENT
[Interface]
PrivateKey = <client-private-key>
Address    = 10.0.0.2/24            # this peer's address inside the tunnel
DNS        = 10.0.0.1

[Peer]
PublicKey  = <server-public-key>    # who we trust (cryptokey routing)
Endpoint   = vpn.example.com:51820  # where to reach them (UDP/51820 default)
AllowedIPs = 0.0.0.0/0              # 0.0.0.0/0 = full tunnel (all traffic)
PersistentKeepalive = 25            # hole-punch through NAT
# 3. Bring the tunnel up and inspect it
$ sudo wg-quick up wg0
$ sudo wg show
interface: wg0
  public key: <client-public-key>
peer: <server-public-key>
  endpoint: 203.0.113.9:51820
  allowed ips: 0.0.0.0/0
  latest handshake: 8 seconds ago      ← tunnel is established
  transfer: 1.21 MiB received, 480 KiB sent

AllowedIPs = 0.0.0.0/0 makes this a full tunnel; restricting it to, say, 10.0.0.0/24 would make it a split tunnel that only protects traffic to the corporate subnet.

Limitations and attacks

A VPN is one layer, and like every layer it has failure modes — assuming it makes you “safe” is the real danger:

Key takeaways

References


Related course pages: Cryptography · Network Security · DNS Security and Privacy · Introduction to Networking · Privacy

🛠️ Maintenance note: WireGuard’s in-kernel status and crypto stack are stable, but verify the wg/wg-quick workflow on the course VM each term. TunnelVision (CVE-2024-3661, disclosed 2024) is current; check whether OS-level mitigations have shipped before presenting it as live.