IPsec (Internet Protocol Security) is a suite of IETF standards that encrypts and authenticates IP traffic between two points, such as two office firewalls, so it can cross the public internet privately. It is the protocol behind most site-to-site VPNs and many remote-access VPNs, and getting a tunnel working mostly comes down to both ends agreeing on the same settings and being able to reach each other's address.
IPsec works at the network layer, underneath applications. Once a tunnel is up, any traffic between the two networks, whether file shares, printers, phone calls or database connections, is protected without each application doing anything. That is why it suits permanent links between offices, data centers and cloud networks. Which kind of VPN a business should choose is a separate question, covered in our guide to business VPN options. This page explains how the protocol itself works.
The parts of IPsec
- IKE (Internet Key Exchange). The negotiation protocol. The two ends use it to prove who they are, agree on encryption settings and create shared keys. IKEv2 is the current version; IKEv1 is older and still found on many devices. IKE runs over UDP port 500.
- Security associations (SAs). The agreements IKE produces. Each SA records the algorithms, keys and lifetime for traffic in one direction, so a working tunnel has at least a pair. Each SA has an ID number called an SPI that travels in every packet.
- ESP (Encapsulating Security Payload). The protocol that carries your traffic. It encrypts the data and adds an integrity check so tampering is detected. ESP is IP protocol 50, a separate protocol number from TCP or UDP.
- AH (Authentication Header). An older option that checks integrity without encrypting. It cannot pass through address translation, and it is rarely used for business VPNs.
IKE phase 1 and phase 2
Tunnel setup happens in two stages. Firewall screens usually call them phase 1 and phase 2, even on IKEv2, where the standard uses different names.
- Phase 1 builds a secure channel for the negotiation itself. The two ends agree on encryption, integrity and Diffie-Hellman settings, exchange keys, and authenticate each other with a pre-shared key or certificates. The result is the IKE SA. In IKEv1 this uses main mode or the less secure aggressive mode.
- Phase 2 builds the SAs that carry your traffic. Inside the phase 1 channel, the ends agree on ESP settings and on which networks the tunnel covers, known as traffic selectors, proxy IDs or the encryption domain depending on the vendor. The result is a pair of IPsec SAs, called child SAs in IKEv2.
- Both phases expire and rekey. Each SA has a lifetime, and new keys are negotiated before it runs out. Phase 1 lifetimes are commonly longer than phase 2.
A rule of thumb for troubleshooting: if phase 1 fails, check the peer addresses, authentication and phase 1 settings. If phase 1 comes up and phase 2 does not, the traffic selectors or phase 2 settings usually differ between the two ends.
What both ends must agree on
When you build a tunnel to a partner, a branch or a cloud network, the two sides exchange a short worksheet. Mismatches in any line are the most common reason a tunnel will not come up.
| Setting | Phase | What to agree |
|---|---|---|
| Peer addresses | 1 | The public IP address of each end |
| IKE version | 1 | IKEv2 where both ends support it |
| Authentication | 1 | Pre-shared key or certificates; a long random key if pre-shared |
| Encryption and integrity | 1 and 2 | Current algorithms such as AES with SHA-2, or AES-GCM |
| Diffie-Hellman group | 1, and 2 if PFS is on | A current group both ends support |
| Perfect forward secrecy (PFS) | 2 | On or off, and which group |
| Lifetimes | 1 and 2 | Matching values, or at least compatible ones |
| Traffic selectors | 2 | The exact local and remote networks, written the same way on both ends |
Avoid outdated options such as DES, 3DES, MD5 and the smallest Diffie-Hellman groups, and check the current guidance from your firewall maker and the other party. Cloud providers publish the settings their VPN gateways accept.
Tunnel mode vs transport mode
Tunnel mode encrypts the entire original packet, including its private source and destination addresses, and wraps it in a new packet addressed between the two firewalls. Site-to-site VPNs use tunnel mode, because the networks behind each firewall stay hidden and private addresses can cross the internet.
Transport mode encrypts only the payload and keeps the original IP header. It is used between two hosts that talk directly, or together with another tunneling protocol such as GRE, which does the wrapping instead.
Firewalls also build tunnels in two styles. A policy-based VPN encrypts traffic that matches a rule. A route-based VPN creates a virtual tunnel interface and sends traffic into it with ordinary routing, which makes failover across two circuits and dynamic routing easier. The two ends can use different styles, as long as their traffic selectors match.
NAT traversal, CGNAT and static IPs
ESP has no port numbers, so a router that translates addresses cannot track it. NAT traversal (NAT-T) solves that. During IKE, the two ends detect any translation between them and switch to UDP port 4500, wrapping each ESP packet in UDP so it passes through. Most firewalls do this automatically, as long as UDP ports 500 and 4500 are allowed.
NAT-T lets an end behind translation start a tunnel. It does not make that end reachable. If a branch is behind carrier-grade NAT, it can usually connect out to a head office with a public address, and the head office cannot start the tunnel back. If both ends are behind CGNAT, a direct tunnel generally will not work. A static IP address on at least one end, ideally the hub, avoids most of this. Dynamic addresses can be handled with dynamic DNS or the firewall's own identity settings, at the cost of more to go wrong.
Performance and packet size
- Encryption speed. Firewalls list a separate IPsec throughput figure, often far below their plain firewall figure. That number, not the circuit speed, often sets the tunnel's ceiling. Our page on the next-generation firewall explains why inspection and encryption figures differ from the headline number.
- Overhead. ESP adds headers, padding and an integrity check, tunnel mode adds a new IP header, and NAT-T adds a UDP header. Packets that were full size before can become too large, which shows up as some applications hanging while others work. Lowering the TCP maximum segment size on the tunnel, known as MSS clamping, is the usual fix.
- Dead peer detection. Each end checks that the other is still answering and tears the tunnel down if it is not, so a backup path can take over.
IPsec vs SSL VPN and the alternatives
| IPsec VPN | SSL/TLS VPN | |
|---|---|---|
| Typical use | Site-to-site; also remote access with IKEv2 clients | Remote access for staff |
| Ports | UDP 500 and 4500, plus ESP | Usually TCP or UDP 443 |
| Works through restrictive guest networks | Sometimes blocked | Usually passes, since it looks like secure web traffic |
| Interoperability | An open standard; different makers' firewalls can connect | Usually tied to one maker's client and gateway |
| Client | Built into most operating systems, or a vendor client | Vendor client or a browser |
For staff access, many businesses are moving to zero trust products that grant access to individual applications instead of a whole network; our guide to zero trust network access explains how. SD-WAN still builds IPsec tunnels between sites, but creates and manages them automatically. Cloud security services built on the SASE model often accept IPsec tunnels from office firewalls as their way in.
How FiberX helps
FiberX gets quotes from several carriers for each site and checks the details that decide whether a tunnel will work: whether the hub has a static IP, whether a backup line sits behind CGNAT, and whether the upload at the hub can carry every branch. If you would rather not manage tunnels yourself, we can quote managed SD-WAN and managed firewall services. The carrier pays us, so there is no markup. Request a quote, or call or text 478-758-8091.