The Intermediary Layer
Most traffic on the internet flows directly: client → server. But a large fraction is mediated — deliberately routed through an intermediary that forwards, transforms, or protects it. Proxies, VPNs, and tunnels are all variations of one idea: put a trusted middlebox in the path and move data through it. What differs is who the middlebox stands for, what layer it works at, and what it protects.
The three questions to ask of any intermediary:
- Whose side is it on? (client’s, server’s, or a neutral third path)
- What layer does it inspect? (L4 transport vs L7 application)
- Does it encrypt? (pass-through vs secure tunnel)
Proxies Revisited
From the DNS & Load Balancing topic you know the core distinction; here’s the full picture:
- Forward proxy — stands for the client. The server sees the proxy’s address, not the client’s. Corporate egress filtering, caching of popular content, content filtering, and privacy/anonymity all use this shape.
- Reverse proxy — stands for the server. The client sees the proxy’s address, not the backend’s. Load balancing, TLS termination, caching, rate limiting, and hiding topology all use this shape.
A SOCKS proxy is the transport-layer forward proxy: it tunnels raw TCP (or UDP) rather than understanding HTTP, so it can carry anything — ssh -D creates one on the fly, letting you route arbitrary traffic through a jump host. Its advantage is generality; its limitation is no application-aware features (no URL routing, no caching).
One more flavor worth naming: a transparent proxy intercepts traffic without the client configuring anything (common in captive portals and office networks) — which is why HTTPS/end-to-end encryption is the standing defense against silent interception.
What a VPN Actually Is
A VPN (Virtual Private Network) creates a secure tunnel between endpoints over an untrusted network, so two sites (or a remote worker and the office) behave as if connected by a private wire. Two defining properties:
- Encryption + authentication — the tunnel is confidential (eavesdroppers see ciphertext) and authenticated (only authorized peers can enter).
- Virtual topology — hosts inside the tunnel use private IPs (
10.0.0.x) that the underlying internet never routes; the tunnel encapsulates one packet inside another.
The encapsulation is the key move: your packet gets wrapped in an outer packet addressed to the VPN server, and the VPN server decapsulates and delivers it. From the network’s point of view, it’s just a stream of encrypted traffic to one address.
Site-to-Site vs Remote Access
| Site-to-site | Remote access | |
|---|---|---|
| Connects | Two office networks (gateway-to-gateway) | One worker → one office |
| Typical user | Routers/edge appliances | Laptops/phones |
| Scale | Whole LANs bridged | Per-device |
| Example | Branch office ↔ HQ via IPsec | WireGuard/OpenVPN client |
Tunneling Protocols Compared
| Protocol | Layer | Crypto | Strength | Weakness |
|---|---|---|---|---|
| IPsec (IKEv2 + ESP) | L3 (packet) | AH/ESP | Battle-tested, standards-based | Complex config; older modes notoriously fiddly |
| WireGuard | L3 (packet) | ChaCha20Poly1305, Curve25519 | Tiny codebase, modern crypto, fast handshake | Fewer enterprise features |
| OpenVPN | L3 (packet, userspace) | TLS | Mature, portable, firewall-friendly (UDP/TCP) | Slower, heavier code |
| SSH tunnel | L7-ish (port forward) | SSH | Trivial to set up | TCP-only, not a real VPN |
| TLS (HTTPS-based) | L7 | TLS | Browser-friendly (used by cloud ZTNA) | Needs a gateway |
WireGuard’s kernel design (~4k lines vs OpenVPN’s ~100k) has made it the default for modern tunnels — lower attack surface, better performance, and a handshake measured in milliseconds. IPsec remains the enterprise interop standard. The modern managed trend is ZTNA (Zero Trust Network Access, see Network Security Fundamentals), which replaces “network-wide tunnel” with per-identity, per-application access — often just TLS to a gateway instead of a full L3 VPN.
NAT and the Tunnel Problem
Network Address Translation (NAT) lets many private hosts share one public IP — but it breaks inbound connections and therefore breaks naive VPNs: the VPN server doesn’t know which internal host a packet belongs to, and a client behind NAT can’t receive inbound packets. Two classic solutions:
- NAT traversal — the client initiates an outbound connection first, keeping a mapping alive at the NAT, then tunnels within it (what most client VPNs do).
- Tunnels that ride TCP/UDP — OpenVPN over UDP/TCP and WireGuard’s UDP are NAT-friendly because they look like ordinary client traffic.
This is also why peer-to-peer systems (BitTorrent, WebRTC) need hole punching — both sides establish outbound mappings, then rendezvous to send through the resulting hole.
The Architecture Decision
| Need | Use |
|---|---|
| Office egress filtering/caching | Forward proxy (or transparent proxy) |
| Protect/load-balance backend servers | Reverse proxy (nginx/HAProxy/Envoy) |
| Tunnel arbitrary TCP through a host | SOCKS via ssh -D |
| Bridge two offices | Site-to-site IPsec |
| Remote worker access | WireGuard/OpenVPN/ZTNA client |
| Inspect/control traffic at L7 | Reverse proxy / API gateway |
| Avoid interception | Always HTTPS; assume proxies are visible to intermediaries |
Practice Trajectory
ssh -D 1080 user@jump-hostthencurl --socks5 localhost:1080 ifconfig.me— confirm the egress IP changed (forward proxy behavior).- Put an nginx reverse proxy in front of a local server;
curl -iand confirm theServerheader no longer leaks the backend. - Stand up WireGuard on two VPSes and ping across the tunnel by private IP;
tcpdumpthe outer interface and confirm you see only UDP 51820. ip tunnel/ip routeinspection on a WireGuard interface — identify the virtual interface and its route table.- Explain to someone the difference between a SOCKS proxy and a VPN in two sentences (transport forwarding vs encrypted L3 tunnel).
When It’s the Right Tool
| Situation | Takeaway |
|---|---|
| Hiding clients from servers | Forward proxy / SOCKS |
| Hiding & protecting servers | Reverse proxy |
| Private network over the internet | VPN tunnel |
| Modern remote access | ZTNA over full-mesh VPN |
| Troubleshooting tunnel issues | Tunnels are encapsulation: debug the outer packet first |