Skip to main content
VPN Security: IPsec IKEv2, WireGuard & Pitfalls
Lesson 9 of 12

VPN Security: IPsec IKEv2, WireGuard & Pitfalls

Evaluate IPsec IKEv2 and WireGuard tunnel architectures, configure modern cryptographic suites, and audit deployments for split-tunneling bypasses, weak PSKs, and DNS or IPv6 leaks.

Advanced 26 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 the IKEv2 control-plane handshake and ESP tunnel-mode encapsulation in IPsec
  • Configure strongSwan and WireGuard using modern AEAD cipher suites and strict traffic selectors
  • Explain how WireGuard cryptokey routing enforces peer identity and prevents inner IP spoofing
  • Audit VPN configurations for split-tunneling exposure, weak pre-shared keys, and DNS or IPv6 leaks

Recommended first: Firewall Configuration, Egress Filtering & HardeningNetwork Segmentation, DMZs, Microsegmentation & NAC

#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_INIT followed by IKE_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-GCM or ChaCha20-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.
IKEv2 handshake and ESP tunnel setupIKEv2 handshake and ESP tunnel setupInitiatorResponderIKE_SA_INIT (cipher proposals, DH public key, nonce)IKE_SA_INIT (chosen suite, DH public key, nonce)IKE_AUTH (identity, cert/EAP auth, traffic selectors)IKE_AUTH (responder auth, Child SA, tunnel IP)ESP encrypted packet (IP proto 50 or UDP 4500)Legacy IKEv1 Aggressive Mode is avoided completely

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:

ini
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:

  1. Outbound: When the kernel routes a packet into wg0, WireGuard matches the destination IP against each peer's AllowedIPs, encrypts it with that peer's session key, and sends it to the peer's UDP endpoint.
  2. Inbound: When wg0 decrypts an incoming packet from a peer, WireGuard verifies that the inner source IP belongs to that same peer's AllowedIPs. 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.
ini
# /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/32

Adding 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:

Checking active WireGuard peers in the lab
$ 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 into 10.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/0 without ::/0 leaves IPv6 traffic flowing unencrypted out the local interface. Similarly, omitting an internal DNS = 10.40.0.2 directive 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/8 or putting AllowedIPs = 10.40.0.0/24 on a client peer in the server config disables least privilege and lets peers spoof sibling tunnel IPs. Pair the VPN interface (wg0 or xfrm0) with nftables forward rules 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 wg0 or IPsec XFRM interfaces as untrusted ingress zones in nftables so VPN users only reach explicitly permitted internal services.
  • Audit handshakes and logs: Monitor journalctl -u strongswan and wg show handshake 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_IKpsk2 cryptography (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, /32 per-peer server AllowedIPs, and nftables forward rules on the gateway.

Knowledge check

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

Practice: test your knowledge