Sub topic 1
VPNs and Tunnelling Explained: Encapsulation, Encryption and Routing
Prerequisites
This chapter assumes basic IP addressing, subnets, default routes, routing tables, TCP and UDP, and a Linux command line.
Refresher: how packets find their way
A host sends an IP packet to a destination address. It checks its routing table and chooses the most specific matching route. If no specific route matches, it uses the default route, usually toward a router.
A router removes the incoming link-layer frame, examines the destination IP address, and forwards the packet using its own routing table. The packet can cross several networks before reaching its destination.
Tunnelling: packets inside packets
Encapsulation puts one packet inside another packet. The original packet is the inner packet. A new outer packet carries it across an intermediate network.
The outer addresses identify the tunnel endpoints. After the packet reaches the remote endpoint, that endpoint removes the outer header and forwards the inner packet.
A tunnel can connect networks that the intermediate network cannot route directly. A VPN is a tunnel that also provides security features.
What a VPN adds to a tunnel
A VPN normally authenticates the peers and protects traffic with cryptography:
- Confidentiality hides the contents.
- Integrity detects changes in transit.
- Authentication verifies the peer or device.
GRE is an example of encapsulation without these protections. IPsec, TLS-based VPNs, and WireGuard combine tunnelling with authentication and encryption.
Overhead, MTU and fragmentation
Every outer header consumes space. The maximum transmission unit, or MTU, is the largest packet a link can carry without fragmentation. A tunnel lowers the usable MTU because the outer headers take part of the original packet's space.
If large packets are dropped and error messages cannot return, the connection may appear partly broken. This is an MTU black hole. Lowering the tunnel MTU or allowing path MTU discovery can fix it.
GRE: a simple tunnel with no protection
GRE, or Generic Routing Encapsulation, creates a virtual interface. Routes send inner packets through that interface, while GRE wraps them in outer IP packets.
sudo ip tunnel add gre1 mode gre local 192.0.2.1 remote 198.51.100.1 ttl 255
sudo ip addr add 10.10.10.1/30 dev gre1
sudo ip link set gre1 up
sudo ip route add 10.20.0.0/16 via 10.10.10.2 dev gre1The remote host needs matching tunnel settings and a route back. GRE is useful for simple routed links, but pair it with IPsec when the traffic requires protection.
Exercise
A tunnel adds 40 bytes of headers to a path whose physical MTU is 1500 bytes. What inner MTU avoids exceeding the path MTU?
Show answer
Use an inner MTU of 1460 bytes or less.