Sub topic 10
Internet VPNs with IPsec: private traffic over a public network
This chapter assumes you know the OSI and TCP/IP models, IPv4 subnetting, static and dynamic routing, and how to read router CLI output. The earlier chapters covered leased lines and MPLS. Both are private services that the provider isolates for you. Here you build privacy yourself, on top of the public internet.
Why use an internet VPN
A branch site can often buy broadband for a fraction of the price of a leased line or an MPLS port. Broadband is faster for the money, and it is available almost everywhere. The cost is that the internet gives no guarantees. The path crosses many networks, any of which can drop, delay, or inspect your packets.
An internet VPN reduces the security problem. It wraps private traffic in an encrypted, authenticated tunnel across the public network. It does nothing for the performance problem, and that difference drives most of the design decisions below.
Common uses:
- Low-cost connectivity for small branches.
- Backup path for an MPLS-connected site.
- Connections to cloud networks, which usually offer IPsec endpoints.
- The encrypted overlay underneath most SD-WAN products, covered in later chapters.
What IPsec provides
IPsec is a suite of protocols that works at the network layer. It provides four services:
- Confidentiality: the payload is encrypted, for example with AES.
- Integrity: a hash-based check detects modification in transit.
- Origin authentication: the receiver knows the packet came from the peer that holds the keys.
- Anti-replay: sequence numbers let the receiver reject copies of old packets.
Two protocols carry the data. ESP (Encapsulating Security Payload, IP protocol 50) encrypts and authenticates. AH (Authentication Header, protocol 51) only authenticates. It breaks when a NAT device rewrites addresses, so almost every deployment uses ESP.
IKE (Internet Key Exchange) is the control protocol. It runs over UDP port 500, negotiates algorithms, authenticates the peers, and generates session keys. Use IKEv2 for new designs. It is simpler and more reliable than IKEv1.
Security associations
A security association (SA) is a one-way agreement between two peers about the algorithms, keys, and lifetime for a flow. Each SA is identified by a Security Parameter Index (SPI) carried in the ESP header. IKEv2 builds two kinds of SA:
- The IKE SA protects the IKE negotiation itself. Peers authenticate here, using a pre-shared key or certificates.
- One or more child SAs (IPsec SAs) protect user traffic. Each direction has its own SA.
Tunnel mode and transport mode
In transport mode, ESP protects only the payload and keeps the original IP header. It suits host-to-host traffic.
In tunnel mode, the whole original packet is encrypted and a new outer IP header is added. The outer header carries the public addresses of the two VPN routers. The inner header, with private addresses such as 10.1.1.0/24, stays hidden. Site-to-site VPNs use tunnel mode.
NAT traversal
ESP has no port numbers, so a NAT device in the path cannot translate it properly. NAT traversal (NAT-T) solves this. When the peers detect NAT during IKE, they switch to UDP port 4500 and wrap ESP inside UDP. This works well and costs 8 more bytes per packet. It matters for branches behind an ISP-supplied router or a carrier-grade NAT.
Two ways to define "interesting traffic"
- Policy-based VPN (crypto map): an access list names which traffic to encrypt. This is simple for one tunnel, but it does not support routing protocols well and the ACLs grow with the number of subnets.
- Route-based VPN (VTI, GRE over IPsec): the tunnel is a routable interface. Anything the routing table sends into it is encrypted. You can run OSPF or BGP across it, and you can fail over by changing routes. This is the usual choice today.
For many sites, add a dynamic overlay such as DMVPN, which lets branches build direct tunnels to each other on demand instead of forcing all traffic through a hub.
A route-based site-to-site example
This Cisco IOS XE configuration builds an IKEv2 VTI tunnel to a peer at 198.51.100.2 and routes a remote LAN into it.
crypto ikev2 proposal IKE-PROP
encryption aes-cbc-256
integrity sha256
group 14
!
crypto ikev2 policy IKE-POL
proposal IKE-PROP
!
crypto ikev2 keyring KR
peer BRANCH
address 198.51.100.2
pre-shared-key local ExampleKey-Change-Me
pre-shared-key remote ExampleKey-Change-Me
!
crypto ikev2 profile IKE-PROF
match identity remote address 198.51.100.2 255.255.255.255
authentication local pre-share
authentication remote pre-share
keyring local KR
!
crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac
mode tunnel
!
crypto ipsec profile IPSEC-PROF
set transform-set TS
set ikev2-profile IKE-PROF
!
interface Tunnel0
ip address 172.16.0.1 255.255.255.252
ip mtu 1400
ip tcp adjust-mss 1360
tunnel source GigabitEthernet0/0
tunnel destination 198.51.100.2
tunnel mode ipsec ipv4
tunnel protection ipsec profile IPSEC-PROF
!
ip route 10.20.0.0 255.255.0.0 Tunnel0The peer needs the mirror image: swapped addresses and the same proposal, keys, and transform set. The tunnel comes up when the first packet matches the route, or you can bring it up manually with a ping.
Overhead and MTU
Tunnel mode adds bytes to every packet. A full-size 1500-byte packet no longer fits in a 1500-byte link MTU. The result is either fragmentation, which hurts throughput, or dropped packets when the Don't Fragment bit is set and ICMP messages are filtered.
For ESP with AES-GCM, the added bytes are:
- Outer IP header: 20 bytes.
- ESP header (SPI and sequence number): 8 bytes.
- Initialization vector: 8 bytes.
- ESP trailer (pad length and next header): 2 bytes, plus padding to a 4-byte boundary.
- Integrity check value: 16 bytes.
- NAT-T UDP header, if used: 8 bytes.
The script below computes the largest inner packet that fits.
def max_inner_packet(link_mtu=1500, nat_t=False):
"""Largest inner IP packet for ESP tunnel mode with AES-GCM-128."""
fixed = 20 + 8 + 8 + 16 # outer IP, ESP header, IV, ICV
if nat_t:
fixed += 8 # UDP 4500 encapsulation
available = link_mtu - fixed
# inner packet + 2-byte trailer + padding must be a multiple of 4
return (available // 4) * 4 - 2
print(max_inner_packet()) # 1446
print(max_inner_packet(nat_t=True)) # 1438Real deployments pick a round, safe value. The configuration above sets the tunnel ip mtu to 1400 and adjusts the TCP maximum segment size (MSS) to 1360. That leaves room for CBC-mode overhead, NAT-T, and a PPPoE link that has an MTU of 1492. MSS adjustment is important because it makes TCP endpoints choose smaller segments during the handshake, so they avoid fragmentation altogether.
Operational problems to expect
| Symptom | Likely cause |
|---|---|
| Tunnel never establishes | Proposal mismatch, wrong peer address or identity, or UDP 500/4500 blocked |
| Tunnel is up, small pings work, large transfers stall | MTU or MSS problem, with ICMP "fragmentation needed" filtered |
| Tunnel drops every few hours | Lifetime mismatch or rekey failure |
| Traffic stops but the tunnel shows up | Peer rebooted and the SA is stale; enable dead peer detection or IKEv2 liveness checks |
| Works from some sites, not others | NAT in the path, or a firewall that drops ESP (protocol 50) without NAT-T |
How it compares to private WAN services
| Property | IPsec over internet | MPLS L3VPN | Leased line |
|---|---|---|---|
| Privacy mechanism | Encryption by you | Logical separation by provider | Physical circuit |
| Performance guarantee | None (best effort) | SLA with QoS classes | Dedicated bandwidth |
| Typical cost | Low | High | High |
| Setup time | Days | Weeks | Weeks to months |
| Failover | Routing over multiple tunnels | Provider-dependent | Needs a second circuit |
| Management effort | Customer manages tunnels | Provider manages core | Simple, but one pair of sites |
Note that MPLS is private but usually not encrypted. If your policy requires encryption, you may run IPsec over MPLS as well.
Limits that lead to SD-WAN
Traditional IPsec VPNs are configured box by box. Each new site needs configuration on both ends or on a hub. Routing changes need manual work. Nothing in the tunnel measures path quality, so a congested broadband link keeps carrying voice until a person intervenes. These gaps are what SD-WAN automates, using the same IPsec tunnels as its encrypted data plane.
Exercise
A branch router has an IPsec tunnel to headquarters. Ping works, and small web requests succeed, but file downloads stall. The branch connects through a PPPoE DSL line with a 1492-byte MTU, and a firewall in the path drops ICMP. What is the most likely cause, and which two settings on the tunnel interface address it?
Show answer
The likely cause is an MTU problem. ESP overhead makes full-size packets too large for the path, and the firewall blocks the ICMP "fragmentation needed" messages that would let path MTU discovery work, so large packets are silently dropped. Lower the tunnel's IP MTU (for example to 1400) and clamp the TCP MSS (for example to 1360 with ip tcp adjust-mss) so endpoints send smaller segments.