#Why this matters
Routing tables and stateful firewalls control packet flow across network boundaries, yet traffic crossing public Wi-Fi, ISP links, or cloud transit remains exposed to interception and tampering. TLS protects individual web sessions, but staff and administrators often need encrypted access to internal subnets, SSH servers, and non-HTTP protocols.
A Virtual Private Network (VPN) builds an encrypted, authenticated tunnel across an untrusted network and ties into the host routing table so private subnets behave like a local private link.
#How tunneling and encapsulation work
A Layer 3 VPN creates a virtual tunnel interface (such as wg0 in WireGuard or tun0 in OpenVPN). Unlike a tap interface that emulates Ethernet frames and carries broadcast chatter, a tun interface routes only Layer 3 IP packets, keeping overhead low.
When an application sends a packet to 10.10.20.15, the OS routing table matches the internal prefix and hands the packet to wg0. The VPN encrypts and authenticates that inner IP packet (headers and payload), then wraps it in an outer packet addressed to the VPN gateway's public IP.
Outer IP, UDP, and cryptographic headers reduce the usable payload size. On standard 1500-byte Ethernet, WireGuard defaults to a 1420-byte MTU. If tunnel MTU is too large and intermediate routers block ICMP Fragmentation Needed messages, small pings work while large TLS handshakes or file transfers stall.
#Topologies and routing modes
VPNs follow two main topologies:
- Remote-access VPN: Individual endpoints connect to a central gateway to reach internal resources from untrusted networks.
- Site-to-site VPN: Two perimeter routers keep a persistent tunnel linking entire office or cloud subnets.
Remote-access deployments choose how much traffic enters the tunnel:
| Mode | Routed prefixes | Strengths | Risks |
|---|---|---|---|
| Split tunnel | Internal CIDRs only (e.g. 10.10.0.0/16) |
Lower gateway load; direct internet access | Local Wi-Fi sees internet traffic; DNS leaks |
| Full tunnel | Default route (0.0.0.0/0) |
Encrypts all Wi-Fi traffic; central egress filtering | Higher gateway load; all traffic needs VPN uptime |
#Modern VPN protocols compared
Three protocol families dominate modern deployments (legacy protocols such as PPTP and unencrypted GRE should not be used):
| Protocol | Transport & typical ports | Key exchange & auth | Core strength |
|---|---|---|---|
| IPsec (IKEv2 + ESP) | UDP 500 / 4500, ESP (proto 50) | IKEv2 certificates or PSK | Native router support for site-to-site |
| OpenVPN | UDP 1194 or TCP 443 | TLS X.509 certificates + MFA | TCP 443 traverses strict outbound firewalls |
| WireGuard | UDP (commonly 51820) | Static Curve25519 keys + PSK | Small codebase, kernel data path, cryptokey routing |
WireGuard uses cryptokey routing: each [Peer] binds a PublicKey to AllowedIPs. Outbound, AllowedIPs chooses which destination prefixes route to that peer. Inbound, after decryption, WireGuard checks that the inner source IP matches AllowedIPs and drops spoofed packets.
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.200.0.2/32
DNS = 10.10.20.53
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = 198.51.100.20:51820
AllowedIPs = 10.10.20.0/24
PersistentKeepalive = 25#Defending and common mistakes
- Treating VPN access as internal trust: A VPN authenticates tunnel entry, not every backend service. Enforce firewall rules between the VPN pool (
10.200.0.0/24) and internal VLANs. - Overlapping
AllowedIPs: Reusing/24across server peers hijacks traffic, while pushing0.0.0.0/0unintentionally breaks local reachability. - Missing NAT keepalives: Stateful NAT gateways drop idle UDP bindings quickly; set
PersistentKeepalive = 25on clients behind NAT. - Unprotected keys and missing revocation: Protect private keys with
0600permissions, pair OpenVPN with MFA, and revoke compromised peers immediately.
#Summary
A VPN protects traffic over untrusted networks by encrypting inner IP packets inside outer transport packets via a virtual tunnel interface. Choosing remote-access versus site-to-site and split versus full tunneling balances privacy, inspection, and bandwidth. Reliable deployments pair IPsec, OpenVPN, or WireGuard with accurate routing scope, proper MTU sizing, NAT keepalives, and least-privilege firewalling behind the gateway.