IPsec

On this page 7

IPsec (Internet Protocol Security) is a suite of protocols that authenticates and encrypts traffic at the IP layer, protecting every packet between two endpoints regardless of which application generated it. In networking and network security, it is the long-established standard for site-to-site VPN tunnels between offices and data centers, and it remains common for remote-access connections and links to cloud networks.

IPsec is not a single protocol but a framework: ESP protects packet contents, AH offers integrity without encryption, and IKE negotiates keys and security parameters. Because it operates below TCP and UDP, applications need no changes, but configuration is more demanding than with newer VPN designs.

How IPsec protects packets

IPsec protects packets by applying a security association (SA), a one-way agreement that defines the algorithms, keys and lifetime for traffic between two peers. Each SA is identified by a Security Parameter Index (SPI) carried in the packet header, so the receiver knows which keys to use.

Setting up a tunnel happens in two phases. In the first, IKE establishes an authenticated, encrypted control channel using a Diffie-Hellman exchange and either pre-shared keys or certificates. In the second, the peers use that channel to create the child SAs that protect actual data traffic, usually one pair per traffic selector, such as a pair of subnets.

The following table summarizes the main components and what each contributes.

ComponentRoleKey detail
ESPEncryption and integrity of the payloadIP protocol 50
AHIntegrity and authentication without encryptionIP protocol 51, breaks with NAT
IKEv2Key exchange and SA negotiationUDP port 500
NAT traversalWraps ESP in UDP behind NAT devicesUDP port 4500
Security association databaseHolds active SAs and keysOne SA per direction
Security policy databaseDecides which traffic must be protectedMatched by addresses, ports, protocol
Building blocks of IPsec

Tunnel mode and transport mode

IPsec has two encapsulation modes, and the choice depends on whether the protected traffic starts and ends at the IPsec peers themselves. Most VPN deployments use tunnel mode.

PropertyTunnel modeTransport mode
What is protectedThe entire original IP packetOnly the payload
New IP headerAdded by the gatewayOriginal header is kept
Typical useSite-to-site and remote-access VPNHost-to-host, often with GRE or L2TP
OverheadAbout 50 to 80 bytes per packetAbout 30 to 60 bytes per packet
Hides internal addressesYesNo
Comparison of IPsec modes

The added headers reduce the room available for payload, so tunnels typically need an adjusted MTU of about 1400 bytes or MSS clamping on the gateways. Ignoring this overhead is one of the most frequent causes of connections that start but then stall.

IPsec compared with other VPN technologies

IPsec competes mainly with WireGuard and TLS-based VPNs, and each makes different trade-offs between interoperability, simplicity and flexibility. The VPN as a concept gets its own page; this comparison focuses on protocol characteristics.

AspectIPsec with IKEv2WireGuardTLS-based VPN
LayerNetwork layerNetwork layerTransport or application layer
InteroperabilitySupported by almost all firewalls and routersGrowing, fewer enterprise devicesUsually vendor-specific clients
Cryptographic agilityMany negotiable suitesOne fixed modern suiteMany suites through TLS
Configuration complexityHighLowMedium
Firewall friendlinessNeeds UDP 500, 4500 or ESPSingle UDP portOften runs over TCP 443
IPsec and neighboring VPN protocols

The decisive advantage of IPsec is interoperability: a branch firewall from one vendor can build a tunnel to a cloud gateway from another, because both implement the same standards. Its main weakness is the large number of parameters that must match exactly on both sides.

A sound IPsec configuration uses IKEv2, modern authenticated encryption and strong Diffie-Hellman groups, and avoids legacy options kept only for compatibility. Both peers must agree on every value, so documenting the proposal on each side is essential.

ParameterRecommendedAvoid
Key exchange versionIKEv2IKEv1 aggressive mode
EncryptionAES-GCM with 256-bit keysDES, 3DES
IntegrityBuilt into GCM, or SHA-256 and aboveMD5, SHA-1
Diffie-Hellman groupGroup 19, 20 or 31Groups 1, 2 and 5
AuthenticationCertificates or long random pre-shared keysShort shared passwords
LifetimesIKE SA about 24 hours, child SA about 1 hourMismatched values per side
Typical modern settings versus legacy settings

Perfect forward secrecy should be enabled for child SAs, so that each rekey performs a new Diffie-Hellman exchange and a compromised key does not expose earlier traffic. Dead peer detection helps both sides notice a failed tunnel and rebuild it quickly.

Typical IPsec problems

Most IPsec failures are negotiation mismatches rather than defects, and the gateway logs usually state which phase failed. Reading them carefully saves much guesswork.

  • Phase one fails: different authentication methods, pre-shared keys or IKE proposals on the two peers.
  • Phase two fails: traffic selectors do not match, for example one side defines a /24 and the other a /23.
  • Tunnel is up but no traffic passes: missing routes, firewall rules, or NAT applied to traffic that should enter the tunnel.
  • Tunnel drops periodically: mismatched lifetimes or rekey behavior between vendors.
  • Large transfers stall: tunnel overhead exceeds the path MTU.

Put simply

IPsec works like an armored courier service between two buildings. Every letter that leaves one office is sealed in a locked box, sent across the open city and unlocked only at the other office. Anyone who intercepts the box on the way sees only that a box is traveling, not what is inside or who inside the building wrote it.

Before the service starts, both offices agree on the locks and exchange the keys in a secure way. The people writing the letters do not need to do anything special, because the protection is applied automatically to everything that passes between the buildings.

In practice

A manufacturing company connects its headquarters network, 10.10.0.0/16, to a cloud virtual network, 10.50.0.0/16, so that its planning software can query a database hosted in the cloud. The network team configures a route-based IPsec tunnel with IKEv2, AES-256-GCM, Diffie-Hellman group 20 and certificate authentication between the headquarters firewall and the cloud VPN gateway.

The tunnel comes up at once, but database exports larger than a few kilobytes hang. A packet capture shows full-size segments disappearing inside the tunnel. The team sets MSS clamping to 1350 bytes on the tunnel interface, after which exports complete normally. A second tunnel to a redundant cloud gateway, with dynamic routing over both, gives the link failover within seconds when one gateway is maintained.