#Why this matters
Firewalls and network segmentation isolate sensitive internal tiers from untrusted networks, yet remote staff and branch offices still need encrypted access across the public internet. A Virtual Private Network (VPN) extends a segmented trust boundary over untrusted links.
When a VPN is poorly designed, it punches a hole straight through your perimeter controls. Legacy cipher negotiation, short pre-shared keys (PSKs), unmonitored split tunneling, and leaked DNS or IPv6 traffic regularly turn VPN gateways into initial access vectors or blind spots. Understanding how modern IPsec IKEv2 and WireGuard operate under the hood lets you configure them securely and audit existing tunnels with confidence.
#IPsec and IKEv2 architecture
IPsec separates key negotiation (control plane) from packet encryption (data plane):
- Control plane (IKEv2, RFC 7296): Uses UDP port 500 (and switches to UDP port 4500 for NAT Traversal, or NAT-T). In two round trips (
IKE_SA_INITfollowed byIKE_AUTH), peers negotiate algorithms, run an ephemeral Diffie-Hellman exchange, authenticate via X.509 certificates, EAP, or a strong PSK, and establish the first Child Security Association (SA) with explicit traffic selectors. Unlike deprecated IKEv1, IKEv2 has no Aggressive Mode that exposes PSK hashes to offline cracking. - Data plane (ESP vs AH): ESP (IP protocol 50, or encapsulated inside UDP 4500 across NAT) provides confidentiality, integrity, and anti-replay protection using modern AEAD suites such as
AES-GCMorChaCha20-Poly1305. AH (IP protocol 51) authenticates outer IP headers without encryption, breaks behind NAT, and is rarely used today. - Tunnel mode vs Transport mode: Tunnel mode wraps the entire original IP packet in a new outer IP header for site-to-site gateways and remote-access VPNs. Transport mode protects only the payload while keeping original IP headers for host-to-host links.
On Linux with strongSwan, modern deployments use swanctl.conf (via the VICI interface) rather than legacy ipsec.conf. Notice how the configuration pins IKEv2, enforces AEAD proposals, uses certificate authentication (pubkey), and scopes local_ts to a single segmented subnet:
connections {
campus-remote {
version = 2
proposals = aes256gcm16-prfsha384-x25519,aes128gcm16-prfsha256-ecp256
local {
auth = pubkey
certs = gw-cert.pem
id = vpn.example.test
}
remote {
auth = eap-tls
}
children {
net-access {
local_ts = 10.30.20.0/24
esp_proposals = aes256gcm16-x25519,aes128gcm16-ecp256
}
}
}
}Avoid CBC-mode ciphers paired with SHA-1 or weak Diffie-Hellman groups (such as MODP-1024); require AEAD (aes256gcm16 or chacha20poly1305) and modern elliptic-curve groups (x25519, ecp256, ecp384).
#WireGuard design and cryptokey routing
WireGuard takes a minimal, opinionated approach inside the Linux kernel. Instead of negotiating cipher suites at runtime, it uses the Noise protocol framework (Noise_IKpsk2) with fixed primitives: Curve25519 for key exchange, ChaCha20-Poly1305 for authenticated encryption, BLAKE2s for hashing, and SipHash24 for internal tables. Removing negotiation eliminates downgrade attacks and keeps the auditable codebase small.
WireGuard's core security mechanism is cryptokey routing. Every peer entry maps a Curve25519 public key to a list of AllowedIPs:
- Outbound: When the kernel routes a packet into
wg0, WireGuard matches the destination IP against each peer'sAllowedIPs, encrypts it with that peer's session key, and sends it to the peer's UDP endpoint. - Inbound: When
wg0decrypts an incoming packet from a peer, WireGuard verifies that the inner source IP belongs to that same peer'sAllowedIPs. If a compromised client tries to spoof another user's tunnel IP, the kernel drops the packet before it reaches local routing or firewall rules.
# /etc/wireguard/wg0.conf (Server gateway on 10.40.0.1/24)
[Interface]
Address = 10.40.0.1/24
ListenPort = 51820
PrivateKey = <server_private_key>
[Peer]
# Analyst laptop - allowed ONLY its single /32 tunnel address
PublicKey = <client_public_key>
PresharedKey = <optional_256bit_psk>
AllowedIPs = 10.40.0.12/32Adding a per-peer PresharedKey mixes symmetric key material into the handshake, adding post-quantum confidentiality against future adversaries who record encrypted handshakes today. Inspect live tunnel state with wg show:
$ sudo wg show wg0
interface: wg0
public key: 9xK3mP2v...labExampleKey...Q=
private key: (hidden)
listening port: 51820
peer: L7rT9wA1...clientExampleKey...M=
preshared key: (hidden)
endpoint: 192.0.2.55:49152
allowed ips: 10.40.0.12/32
latest handshake: 18 seconds ago
transfer: 1.42 MiB received, 4.88 MiB sent| Dimension | IPsec IKEv2 (strongSwan) | WireGuard |
|---|---|---|
| Cryptography | Negotiated (pin AEAD + ECDH) | Fixed (Noise_IKpsk2, ChaCha20-Poly1305) |
| Transport ports | UDP 500, UDP 4500, IP proto 50 | Single UDP port (commonly 51820) |
| Enterprise user auth | Native EAP-TLS, RADIUS, MFA hooks | Static Curve25519 keys (needs wrapper for SSO/MFA) |
| Key privacy / IP assignment | Dynamic virtual IPs via CP payload | Static tunnel IPs in base config |
#Critical VPN pitfalls and auditing
Even strong cryptography fails when routing, authentication, or segmentation is misconfigured:
- Split-tunneling bypasses: Setting
AllowedIPs = 10.30.0.0/16(split tunnel) sends internal traffic through the VPN and general internet traffic directly through the local Wi-Fi or ISP gateway. Without a strict host firewall on the endpoint, a compromised laptop acts as a dual-homed bridge from an untrusted café network straight into10.30.0.0/16, bypassing corporate egress inspection. Full-tunnel mode (0.0.0.0/0, ::/0) routes all traffic through the central firewall and monitoring stack, at the cost of higher gateway bandwidth. - DNS and IPv6 leaks: A full-tunnel IPv4 config that specifies
AllowedIPs = 0.0.0.0/0without::/0leaves IPv6 traffic flowing unencrypted out the local interface. Similarly, omitting an internalDNS = 10.40.0.2directive lets the endpoint query the local ISP's resolver, leaking internal hostnames. - Weak PSKs and legacy IKEv1: Supporting IKEv1 or short, human-chosen PSKs enables offline dictionary attacks. Always disable IKEv1 and authenticate peers with X.509 certificates, EAP-TLS, or high-entropy machine keys.
- Over-broad traffic selectors and missing gateway firewalls: Granting
local_ts = 10.0.0.0/8or puttingAllowedIPs = 10.40.0.0/24on a client peer in the server config disables least privilege and lets peers spoof sibling tunnel IPs. Pair the VPN interface (wg0orxfrm0) withnftablesforwardrules enforcing zone segmentation.
#Defending and hardening VPN deployments
- Standardise on IKEv2 or WireGuard: Disable PPTP, L2TP/IPsec with weak defaults, and IKEv1 completely.
- Enforce strong identity and revocation: Pair IPsec with EAP-TLS/PKI and MFA, maintain Certificate Revocation Lists (CRLs) or OCSP checks, and remove WireGuard peer blocks immediately when devices are lost or decommissioned.
- Firewall the tunnel interface: Treat
wg0or IPsec XFRM interfaces as untrusted ingress zones innftablesso VPN users only reach explicitly permitted internal services. - Audit handshakes and logs: Monitor
journalctl -u strongswanandwg showhandshake timestamps for failed authentication bursts, unexpected endpoints, or stale unused peers.
#Summary
- IPsec IKEv2 separates control-plane authentication and key exchange (UDP 500/4500) from ESP data-plane encryption, avoiding legacy IKEv1 Aggressive Mode risks.
- WireGuard uses fixed
Noise_IKpsk2cryptography (Curve25519, ChaCha20-Poly1305, BLAKE2s) and enforces peer routing and source-IP validation through cryptokey routing (AllowedIPs). - Most real-world VPN incidents stem from operational pitfalls: unmonitored split tunneling, weak shared PSKs, IPv6/DNS leaks, and missing firewall segmentation behind the tunnel.
- Hardened VPNs combine strong AEAD suites, certificate or MFA-backed identity,
/32per-peer serverAllowedIPs, andnftablesforwardrules on the gateway.