← Study home

๐Ÿ” How a VPN Actually Works

Deep-dive reference on Virtual Private Networks โ€” the real mechanics (tunneling, IPsec, IKE, crypto), not just "it's a secure tunnel." Builds on Networking (encapsulation ยง4, TLS handshake ยง2, NAT ยง7, IPsec-at-L3). Tied to AWS Site-to-Site VPN / Client VPN for AWS-Cloud-Practitioner Domain 3.

โ† back to Networking ยท DevOps ยท AWS-Cloud-Practitioner


The core idea

A VPN (Virtual Private Network) makes two endpoints behave as if they're on the same private LAN, even though traffic between them crosses the public, untrusted internet. Three pillars:

  1. Tunneling (encapsulation) โ€” wrap each packet inside another so private addressing is hidden and the internet routes it between two public endpoints.
  2. Encryption โ€” scramble the payload so a sniffer sees gibberish.
  3. Authentication + integrity โ€” each end proves its identity (no tunneling to an imposter) and every packet is integrity-checked (no tampering in flight).

One-liner: a VPN is an encrypted, authenticated tunnel that carries private network traffic across a public network as if it were local.

Two types

Remote-access (client-to-site) Site-to-site
Connects One device โ†’ a private network Two whole networks
Examples Corporate "connect to office", consumer privacy VPNs, AWS Client VPN On-prem โ†” AWS VPC, office โ†” office, AWS Site-to-Site VPN
Your-side endpoint VPN client software on the device A VPN gateway/router (no per-device software)
Typical tech TLS-based (OpenVPN), WireGuard, IKEv2 IPsec

The AWS exam's "VPN" (the VGW one) is site-to-site.

Pillar 1 โ€” Tunneling / encapsulation

A VPN does an extra wrap beyond normal encapsulation (Networking ยง4): it puts a whole finished IP packet inside the payload of a new packet.

Original packet (inside the private network):
  [IP: 10.0.1.5 โ†’ 192.168.2.8][TCP][data]

After IPsec tunnel-mode encapsulation:
  [IP: 198.51.100.7 โ†’ 203.0.113.20]   โ† new OUTER header (the two gateways' PUBLIC IPs)
     [ESP header]
        [ ENCRYPTED { [IP:10.0.1.5 โ†’ 192.168.2.8][TCP][data] } ]  โ† whole original packet, encrypted
     [ESP auth/trailer]

The internet sees only the outer header (public IP A โ†’ public IP B). Private addressing + data are encrypted inside and invisible. That's the "virtual private" part.

Pillars 2 & 3 โ€” encryption + authentication (same pattern as TLS)

Mirrors the TLS handshake (Networking ยง2): asymmetric crypto to bootstrap, symmetric to do bulk work.

Protocol landscape

Protocol Layer Used for Notes
IPsec L3 Site-to-site (+ IKEv2 remote-access) The classic. What AWS Site-to-Site VPN uses.
TLS/SSL VPN (OpenVPN, AnyConnect) rides TLS Remote-access Often on port 443 to pass firewalls. AWS Client VPN is OpenVPN-based.
WireGuard L3 (UDP) Modern everything Tiny codebase, fixed modern crypto (ChaCha20 / Curve25519), roaming-friendly, "cryptokey routing" (peer = its public key).
PPTP / L2TP / SSTP various Legacy PPTP broken/dead; L2TP usually L2TP/IPsec.

IPsec deep dive (what AWS uses)

A suite with two jobs: negotiate keys (IKE), then protect data (ESP/AH).

IKE (Internet Key Exchange) โ€” the handshake, two phases

ESP vs AH

Transport vs tunnel mode

Security Association (SA)

A one-way agreement (cipher + keys + rules for one direction). A working tunnel needs two SAs (one each way). Identified by an SPI (Security Parameter Index) in the ESP header so the receiver picks the right keys.

NAT traversal (NAT-T)

Plain ESP has no ports โ†’ breaks crossing a NAT (Networking ยง7). NAT-T wraps ESP in UDP 4500 so the NAT has a port to track. Needed because nearly every on-prem router is behind NAT (AWS handles it).

End-to-end: a packet through a site-to-site VPN

  1. Host A (10.0.1.5) โ†’ Host B (192.168.2.8) on the remote net.
  2. A's routing: "192.168.2.0/24 โ†’ VPN gateway" โ†’ packet goes to Gateway A.
  3. Gateway A matches IPsec policy โ†’ encrypts the whole packet (ESP) + wraps it [GW-A public IP โ†’ GW-B public IP].
  4. Crosses the internet โ€” sniffers see only an encrypted blob between two public IPs.
  5. Gateway B authenticates (integrity check), decrypts, recovers the original packet.
  6. Gateway B forwards it onto its LAN to Host B.
  7. Return traffic = exact reverse (other SA).

Remote-access mechanics (laptop / consumer VPN)

Geo-unblocking โ€” "watch another country's content"

Same machinery, one twist: pick a full-tunnel exit server in country X, and your traffic reaches the internet from that country's IP. - Why it works = IP geolocation. Your public IP must be real/routable (it's the return address). IP blocks are allocated by region; commercial DBs (e.g. MaxMind) map IP range โ†’ country. Sites just look up your exit IP. No VPN โ†’ ISP's India IP (you look Indian). VPNโ†’US server โ†’ server's US IP (you look American). You don't hide your location, you borrow the exit node's. - Flow: You (India) โ†’ encrypted full tunnel โ†’ VPN server (USA) makes the request from its US IP โ†’ Netflix sees a US IP โ†’ serves the US catalog โ†’ response back through the tunnel. - DNS must go through the tunnel too โ€” else a query to your real ISP resolver = a DNS leak that exposes your true location. VPN pushes its own resolvers. - Why it breaks: streaming services run VPN detection โ€” blocklists of known datacenter/VPN IP ranges โ†’ "you appear to be using a proxy/unblocker." Providers counter with rotating + residential IPs. Permanent cat-and-mouse (same server works one week, not the next). - Contrast: this is full tunnel + remote-access (disguise location); a typical corporate OpenVPN is split tunnel (reach private resources, only some traffic in). Opposite goals, same tech.

AWS angle (exam-relevant)

AWS Site-to-Site VPN = textbook IPsec tunnel mode: - Customer Gateway (CGW) = resource describing your side (on-prem router public IP, BGP ASN). - Virtual Private Gateway (VGW) = the AWS side, attached to the VPC (or attach to a Transit Gateway for many VPCs). - AWS provisions two tunnels to two endpoints for HA/redundancy. - Routing static or dynamic (BGP); IPsec (IKE + ESP), encrypted, over the public internet.

AWS Client VPN = managed remote-access flavor (OpenVPN/TLS) for individual users reaching the VPC.

Exam nuance: Direct Connect alone is private but NOT encrypted (dedicated physical line, no tunnel). Need dedicated line and encryption โ†’ run a VPN over Direct Connect. Common distractor. See AWS-Cloud-Practitioner Domain 3 connectivity menu.

Worked example โ€” corporate OpenVPN (remote-access), and a common confusion

OpenVPN is remote-access + TLS-based โ€” it has NO Virtual Private Gateway. VGW is an AWS site-to-site IPsec construct (two networks); a person on a laptop logging in is remote-access. The box that feels like a "gateway" in an OpenVPN setup is just the OpenVPN server / concentrator (typically an instance/appliance inside the company's AWS VPC).

OpenVPN (typical corporate) AWS Site-to-Site VPN (VGW)
Type Remote-access (a person) Site-to-site (two networks)
Tech TLS/SSL (OpenSSL certs) IPsec (IKE + ESP)
Your side OpenVPN client app A router/gateway
Concentrator An OpenVPN server A Virtual Private Gateway

Corrected step-by-step flow: 1. Auth happens ONCE at tunnel setup โ€” mutual TLS: server cert + client cert (+ usually username/password, often MFA). Not per-request. 2. Server assigns a virtual IP from the VPN pool (e.g. 10.8.0.6), bound to a TUN interface on your laptop. 3. Server pushes routes to your machine ("corporate ranges โ†’ the tun interface"). The send-side routing lives on your box, not the destination server. (Split tunnel = only corp ranges; full = everything.) 4. You hit an internal app โ†’ OS matches a pushed route โ†’ packet into TUN โ†’ OpenVPN encrypts โ†’ ships to the OpenVPN server. 5. OpenVPN server decrypts + forwards into the VPC/corp network. Return routing to your virtual IP is handled by the OpenVPN server โ€” either a route for the VPN pool points back at it, or it NATs your traffic to its own IP (so the app server never even knows your 10.8.0.6 exists).

The misconception to avoid: the destination app server does not list your virtual IP in its routing table, and there is no VGW authenticating each request. Auth is one-time (mutual TLS); the OpenVPN server is the only component that knows your virtual IP and does the routing/NAT on both ends.

VPN vs neighbors + gotchas


Source

Taught in the AWS CLF-C02 study session, 2026-06-29, off the back of AWS-Cloud-Practitioner Module 5 (Networking). Mechanics-level companion to the exam-level VPN coverage in the hub's Domain 3.