Skip to main content

Module 15: VPNs & Tunneling

VPNs (Virtual Private Networks) create secure, encrypted connections over public networks. This module covers VPN types, tunneling protocols, and real-world implementations.
VPN Tunnel Architecture
Estimated Time: 3-4 hours
Difficulty: Intermediate
Prerequisites: Module 7 (Security basics), Module 10 (NAT)

15.1 What is a VPN?

A VPN extends a private network across a public network, allowing users to send and receive data as if connected to the private network directly. The analogy is a sealed, private tunnel through a public highway. Cars (packets) entering the tunnel are visible to everyone on the highway — but no one can see what is inside the tunnel or tamper with its contents. When a car exits the tunnel on the other end, it is on the private road (network) as if it had always been there.

Without VPN

With VPN


15.2 VPN Types

Remote Access VPN

Individual users connect to a corporate network.
Use Cases:
  • Work from home
  • Traveling employees
  • Contractors accessing internal systems

Site-to-Site VPN

Connects two networks together permanently.
Use Cases:
  • Connect branch offices
  • Connect on-premises to cloud (AWS VPN)
  • Merge networks after acquisition

Client-to-Site vs Site-to-Site


15.3 Tunneling Protocols

IPsec (Internet Protocol Security)

Industry standard for site-to-site VPNs. Two Modes:
IPsec Components: IPsec Phases: Think of the two phases like establishing diplomatic relations. Phase 1 is the countries agreeing on which language to speak and verifying each other’s credentials (authentication). Phase 2 is negotiating the actual terms of the treaty (encryption parameters for the data tunnel). If Phase 1 fails, Phase 2 never starts.

What an IPsec packet looks like on the wire


OpenVPN

Open-source, widely used for remote access. Characteristics:
  • Uses OpenSSL library
  • TCP or UDP (UDP preferred)
  • Port 1194 by default (can use 443 to bypass firewalls)
  • Certificate-based authentication

WireGuard

Modern, fast, simple VPN protocol. WireGuard has rapidly become the preferred choice for new VPN deployments due to its simplicity and performance. Advantages:
  • ~4,000 lines of code (vs 100,000+ for OpenVPN) — a smaller codebase means fewer bugs and a smaller attack surface. The entire codebase is auditable by a single person.
  • Built into the Linux kernel (since 5.6) — no user-space daemons needed, which means better performance.
  • Faster than IPsec and OpenVPN in most benchmarks — lower latency and higher throughput due to its minimal, efficient design.
  • Uses modern cryptography only (Curve25519, ChaCha20, Poly1305, BLAKE2s) — no cipher negotiation, which eliminates downgrade attacks. The trade-off is that if any of these algorithms are ever broken, WireGuard must be updated (crypto agility is deliberately sacrificed for simplicity).

SSL/TLS VPN

VPN over HTTPS - works through any firewall. Types:
  • Portal VPN: Browser-based access to web apps
  • Tunnel VPN: Full network access (like OpenVPN)
Advantage: Uses port 443 (HTTPS) - almost never blocked.

Protocol Comparison

Never use PPTP. Its encryption has been broken and traffic can be decrypted.

15.4 Split Tunneling

Full Tunnel

All traffic goes through VPN.
Pros: Maximum security, all traffic protected Cons: Slower, uses company bandwidth for everything

Split Tunnel

Only specific traffic goes through VPN.
Configuration Example (WireGuard):
Pros: Faster, saves bandwidth Cons: Non-VPN traffic is unprotected
Practical scenario — when split tunneling goes wrong: An employee uses split tunnel VPN so personal browsing goes direct. But their company laptop also runs a local database GUI that connects to the corporate database over VPN. One day, malware on a website infects their machine via the direct (unprotected) path. Because the VPN tunnel is active, the malware can now reach the corporate database. This is the fundamental trade-off: split tunneling saves bandwidth but creates a bridge between the untrusted internet and the trusted corporate network. Mitigate this with endpoint security (antivirus, host firewall) and network segmentation that limits what VPN clients can access.

15.5 VPN in the Cloud

AWS Site-to-Site VPN

Connect on-premises network to AWS VPC.
Components:
  • Virtual Private Gateway (VGW): AWS side endpoint
  • Customer Gateway (CGW): Your side endpoint
  • VPN Connection: Two IPsec tunnels (for redundancy)

AWS Client VPN

For remote access to AWS resources.

15.6 VPN Security Considerations

Authentication Methods

Best Practices

Use Strong Encryption

AES-256, ChaCha20. Avoid 3DES, DES, or anything “export grade.”

Enable MFA

Add second factor for VPN authentication.

Certificate Auth

Use certificates instead of pre-shared keys for better security.

Limit Access

Use split tunneling wisely. Apply least privilege.

15.7 Other Tunneling Methods

SSH Tunneling

Create encrypted tunnels using SSH.
Use Cases:
  • Access database behind firewall
  • Quick temporary secure access
  • Bypass network restrictions

GRE (Generic Routing Encapsulation)

Encapsulates various network layer protocols inside point-to-point links.
Note: GRE provides no encryption. Often combined with IPsec.

VXLAN (Virtual Extensible LAN)

Overlay network for data centers. Extends L2 network over L3.
Use Case: Connect VMs/containers across different physical networks as if on same L2 network.

15.8 Troubleshooting VPN Issues


15.9 Key Takeaways

VPN = Secure Tunnel

Encrypts traffic over untrusted networks.

Choose Right Protocol

WireGuard for speed, OpenVPN for compatibility, IPsec for site-to-site.

Split Tunnel Carefully

Balance security vs. performance based on use case.

Never Use PPTP

It’s broken. Use modern protocols only.

Next Module

Module 16: Real-World Networking Scenarios

Walk through complete networking scenarios from request to response.