Why do most VPN protocols work on the Transport Layer and not on the Network Layer instead?
Most VPN/tunnel protocols transport (encapsulate, protect) network layer (IP) or sometimes link layer (Ethernet, PPP) protocols. The main exception is IPsec in transport mode which encapsulates (protects) the transport layers.
However, many VPN/tunnel protocols work on top of a transport layer (UDP, TCP) or some higher (application) layers (TLS tunnels) and not directly on top of the network layer (IP). Some reasons might include:
- this approach is friendlier with NATs and firewalls;
- this makes it is easier to run several instances of the same service on different ports;
- adding a new protocol directly on top of IP requires the allocation of a a protocol number whereas you can always run your transport-based service using some ephemeral port (WireGuard does no have any reserved port).
Let's look at ESP (IPSec) transport mode:
[... ]
[TCP,UDP,...]
[ESP ]
[IP ]
ESP transport
It works on top of the network layer (IP) and protects the transport layers (TCP, UDP, etc.). The source and destination IP addresses are not protected but an MITM does not know which transport protocol is used and, which ports are used.
Now let's look at ESP (IPSec) tunnel mode:
[... ]
[TCP,UDP,...]
[IP ] <- inner IP
[ESP ]
[IP ] <- outer IP
ESP tunnel
It works on top of the network layer (IP) and protects a tunneled network layer (IP). The outer IP header contains the IP addresses of the tunnel endpoints: this information is available to a MITM. However, the outer packet which contains the address and source IP addresses of the peers is protected.
IPSec ESP can work on top of UDP as well:
[... ]
[... ] [TCP,UDP,...]
[TCP,UDP,...] <- inner transports [IP ] <- inner IP
[ESP ] [ESP ]
[UDP ] <- outer transport [UDP ]
[IP ] [IP ] <- outer IP
IPsec ESP/UDP IPsec ESP/UDP
transport tunnel
In transport mode, it works on top of a transport layer (UDP) and protects the transport layers. Not that the ports of the outer transport (UDP) layer does not need to match with the ports of the inner transport layers.
In tunnel mode, it works on top the of a transport layer (UDP) and protects the network layer (IP).
OpenVPN, WireGuard (and the OpenSSH tunnel mode) are similar in this regard:
[... ] [... ]
[TCP,UDP,...] [TCP,UDP,...]
[IP |TLS ] [IP ] [IP ] <- inner IP
[OpenVPN ] [WireGuard ] [SSH ]
[TCP or UDP ] [UDP ] [TCP ]
[IP ] [IP ] [IP ] <- outer IP
OpenVPN WireGuard OpenSSH tunnel
(TUN mode) (TUN mode)
These ones work on top of a transport layer (TDP or UDP) and protect the network layer (IP).
For completeness, OpenVPN (and OpenSSH) can transport a Ethernet frames (link layer) as well:
[... ]
[Ethernet|TLS] [Ethernet]
[OpenVPN ] [SSH ]
[TCP or UDP ] [TCP ]
[IP ] [IP ]
OpenVPN OpenSSH
(TAP mode) (TAP mode)
Examples of TLS tunnels include MS-SSTP and FortiSSL:
[... ]
[TCP,UDP,...] [... ]
[IP ] [TCP,UDP,...]
[PPP ] [IP ]
[SSTP ] [PPP ]
[(HTTP) ] [(HTTP) ]
[TLS ] [TLS ]
[TCP ] [TCP ]
[IP ] [IP ]
MS-SSTP
The tunnel works on top of TLS/HTTP(S) and transport PPP (link layer)
(which itself probably always transport only IP traffic):
Summary
Tunnel type |
Works on top of |
Transports/encapsulates |
ESP transport mode |
IP |
TCP, UDP, etc. |
ESP tunnel mode |
IP |
IP |
ESP/UDP transport mode |
UDP |
TCP, UDP, etc. |
ESP/UDP tunnel mode |
UDP |
IP |
OpenVPN TUN |
UDP or TCP |
IP |
OpenSSH TUN |
TCP |
IP |
OpenVPN TAP |
UDP or TCP |
Ethernet |
OpenSSH TAP |
TCP |
Ethernet |
Wireguard |
UDP |
IP |
MS-SSTP |
(HTTP)/TLS/TCP |
IP/PPP |
FortiSSL |
(HTTP)/TLS/TCP |
IP/PPP |