Skip to main content
VPN Architecture & Encrypted Tunnels
Lesson 9 of 11

VPN Architecture & Encrypted Tunnels

Understand how VPNs encapsulate and encrypt IP packets across untrusted networks, compare IPsec, OpenVPN and WireGuard, and audit a WireGuard peer configuration safely.

Intermediate 22 min Networking
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Explain how VPN encapsulation wraps inner IP packets inside encrypted outer transport packets
  • Compare remote-access and site-to-site topologies as well as split-tunnel and full-tunnel routing
  • Differentiate IPsec (IKEv2/ESP), OpenVPN and WireGuard architectures and key-exchange models
  • Validate a WireGuard peer configuration for AllowedIPs scope, endpoint reachability and key separation

Recommended first: Routing Tables, Gateways, NAT & VLANsFirewalls, Stateful Filtering & Rule OrderHTTP/HTTPS Requests, Methods & TLS Overview

#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.

Packet encapsulation across a Layer 3 VPN tunnelPacket encapsulation across a Layer 3 VPN tunnelClient AppTunnel Interface ...VPN GatewayInternal ServerInner packet 10.200.0.2 -> 10.10.20.15VPN encrypts inner packet and adds outer UDP/IP headerOuter UDP 192.0.2.50:51234 -> 198.51.100.20:51820Gateway verifies tag, decrypts inner packet, checks firewallInner packet 10.200.0.2 -> 10.10.20.15

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.

Example WireGuard client configuration (lab placeholders)
[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 /24 across server peers hijacks traffic, while pushing 0.0.0.0/0 unintentionally breaks local reachability.
  • Missing NAT keepalives: Stateful NAT gateways drop idle UDP bindings quickly; set PersistentKeepalive = 25 on clients behind NAT.
  • Unprotected keys and missing revocation: Protect private keys with 0600 permissions, 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.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge