Sub topic 3
What a VPN adds to a tunnel
This chapter assumes you know IP addressing and subnets, how a routing table and a default route work, and the difference between TCP and UDP. It also assumes you can use a Linux command line. The previous chapter showed that a tunnel wraps one packet inside another. Here we ask what must be added to that wrapping before you can call it a virtual private network (VPN).
A tunnel is a delivery mechanism
A tunnel is a pair of endpoints that agree to carry packets for each other. The sender puts an inner packet inside an outer packet. The outer packet crosses a network that may not know how to route the inner one. The receiving endpoint removes the outer header and forwards the inner packet.
That mechanism alone gives you reachability. It does not give you privacy, and it does not tell you who is on the other end. A GRE tunnel, for example, will carry private 10.x addresses across the internet. Anyone who can capture the outer packets can read the inner ones, and anyone who can send a GRE packet to the endpoint can inject traffic into your network.
A VPN is a tunnel plus security properties. The word "private" in the name is a claim about those properties, so it is worth listing what they are.
The four things a VPN adds
| Property | Question it answers | Without it |
|---|---|---|
| Peer authentication | Is the other endpoint really who it claims to be? | Anyone can pose as the remote site |
| Confidentiality | Can an observer on the path read the inner packets? | Contents are visible to every router in between |
| Integrity | Was a packet modified in transit? | An attacker can alter or forge inner packets |
| Replay protection | Is this a copy of an old packet? | An attacker can resend captured packets |
The later chapters on cryptography and key exchange explain how these are achieved. For now, treat them as a checklist. A protocol that is called a "VPN" but skips one of these should be examined closely.
Some products also add a fifth feature: management of addresses and configuration. A remote-access VPN usually assigns the client an inner address and pushes routes and DNS servers. This is not a security property, but you will meet it in every real deployment, and it affects how traffic flows.
Seeing the difference on the wire
You can check whether a tunnel is only a tunnel by capturing on the physical interface, not on the tunnel interface. The following commands assume the physical interface is eth0.
# GRE: inner packets are visible in the payload
sudo tcpdump -ni eth0 -X ip proto 47
# WireGuard: only opaque UDP datagrams are visible
sudo tcpdump -ni eth0 -X udp port 51820In the GRE capture, the hex dump shows the inner IP header and, for unencrypted protocols, readable application data. In the WireGuard capture, you see UDP datagrams between the two public addresses and a payload that looks random. The outer headers are always visible. Encryption hides the inner packet, not the fact that two hosts are talking, when they talk, or how much data moves.
Two common shapes: site-to-site and remote access
VPNs are usually deployed in one of two shapes. The difference is who the endpoints are, and this decides how routing and authentication are set up.
Site-to-site
A site-to-site VPN joins two networks. The endpoints are gateways, typically a router or firewall at each office. Hosts inside the offices know nothing about the VPN. They send packets to a remote subnet as they would to any other destination, and the gateway does the encapsulation.
Key properties of this shape:
- The tunnel is usually permanent and often brought up as soon as the gateways boot.
- Authentication is between devices, using pre-shared keys or certificates provisioned by an administrator.
- Each gateway needs a route to the other site's subnet. If the two sites use overlapping address ranges, such as both using 192.168.1.0/24, the VPN will not work without address translation or renumbering.
- Traffic between a host and its own gateway is not protected by the VPN. It crosses only the trusted local network.
Remote access
A remote-access VPN connects one device, such as a laptop, to a network. One endpoint is a VPN client on the device, and the other is a concentrator or server at the organisation. The client creates a virtual interface, receives an inner address, and routes some or all of its traffic through it.
Key properties of this shape:
- The tunnel is brought up on demand and may disappear when the laptop sleeps or changes network.
- Authentication often involves a person, using a password, a one-time code, or a certificate on the device. The VPN may check both the user and the device.
- The client's outer address changes as it moves between Wi-Fi, mobile and home networks. The server cannot assume a fixed peer address.
- The client is frequently behind NAT, which affects the choice of protocol. A later chapter covers this.
Many systems blur the line. A WireGuard peer on a home router is a site-to-site endpoint, while the same software on a phone is remote access. The protocol is the same. What changes is whether the peer represents a whole subnet or a single device.
What the endpoint actually does
On each packet, a VPN endpoint performs the same sequence, in either shape. Understanding it helps you debug later.
- The operating system looks up the destination in the routing table. If the best route points at the VPN interface, the packet goes to the VPN software instead of the network card.
- The VPN software decides which peer the packet belongs to, using the destination address or a policy.
- It authenticates and encrypts the inner packet, adding a sequence number or similar value for replay protection.
- It wraps the result in an outer packet addressed to the peer's public address and hands it to the normal network stack.
- The outer packet is routed using the routing table again, this time to the physical interface.
The routing table is consulted twice. The first lookup chooses the tunnel. The second lookup, for the outer packet, must not choose the tunnel again, or packets would loop. This is why VPN clients that send all traffic through the tunnel add a specific route to the VPN server's public address that bypasses the tunnel.
The receiving side reverses the steps. It checks authenticity before it trusts the inner packet. A packet that fails authentication is dropped silently in most designs, so a misconfigured key shows up as "nothing happens" rather than an error message.
Where the tunnel sits in the stack
VPN protocols differ in which layer they wrap, and this affects what they can carry.
- Layer 3 tunnels carry IP packets. IPsec and WireGuard work this way. They are efficient and fit naturally with routing.
- Layer 2 tunnels carry Ethernet frames. They can bridge two LANs so broadcasts and non-IP protocols cross, but they bring broadcast traffic across the link and make it larger.
- Application-layer forwarding, such as an SSH port forward, carries individual TCP connections. It is not a VPN in the full sense, because only the forwarded ports are reachable.
Later chapters compare these in detail. For this chapter, remember that "VPN" describes the set of properties and the deployment, not one protocol.
Common mistakes at this stage
- Assuming a tunnel interface that is up means the VPN works. A GRE interface shows
UPeven when the peer is unreachable, because GRE has no handshake. A VPN with a handshake, such as WireGuard or IPsec, can tell you whether the peer authenticated. Check the handshake time, not the interface flag. - Assuming encryption covers the whole path. In a site-to-site VPN, the traffic is protected only between the gateways. In a remote-access VPN, it is protected only between the client and the concentrator. Traffic beyond the concentrator travels as normal.
- Confusing authentication with authorisation. A VPN proves a peer holds a valid key. It does not decide what that peer may reach. Once connected, a client can often reach everything the routes and firewall allow, so filtering on the inner side is still needed.
- Overlapping subnets. If the home network and the office both use 192.168.1.0/24, the client's routing table cannot tell which one a packet is meant for.
Summary
A tunnel supplies reachability by encapsulation. A VPN adds peer authentication, confidentiality, integrity and replay protection to that tunnel. It is deployed either between two gateways to join networks, or between a device and a gateway to give one host access. In both cases the endpoint relies on the routing table to send traffic into the tunnel, and the protection ends at the tunnel's endpoints.
Exercise
A GRE tunnel between two offices shows both interfaces as UP and pings across it work. A colleague says the offices are now "on a VPN". You capture on the physical interface and see the inner ICMP packets in clear text. Which of the four VPN properties are missing, and what does the capture prove about each?
Show answer
All four are missing: peer authentication, confidentiality, integrity and replay protection. The clear-text inner packets prove the lack of confidentiality directly. Because GRE has no keys or handshake, the receiver cannot verify who sent a packet, so a third party who can send GRE packets to the endpoint can inject traffic. Likewise, nothing detects modification or replay. This is a tunnel, not a VPN, until a layer such as IPsec is added.
Exercise
A laptop on a remote-access VPN sends a packet to 10.2.0.30, a host in the office. Explain why the laptop's routing table is consulted twice, and what would go wrong if the second lookup chose the VPN interface.
Show answer
The first lookup matches the route for the office subnet and selects the VPN interface. After encryption and wrapping, the outer packet is addressed to the VPN server's public address, and the operating system looks up that destination. If that lookup also chose the VPN interface, the outer packet would be wrapped again and sent back into the tunnel, causing a loop and no traffic reaching the server. VPN clients avoid this by adding a specific route for the server's public address through the physical interface.