IPsec – ESP, AH, IKE Phases, Tunnel Mode & VPN Configuration
1. What Is IPsec?
IPsec (Internet Protocol Security) is an open-standard framework of protocols that secures IP communications by providing authentication, integrity, and encryption at the network layer (Layer 3). Unlike application-layer security (TLS/HTTPS), IPsec protects all traffic regardless of which application generates it — making it transparent to applications and ideal for building VPNs (Virtual Private Networks).
IPsec operates between two peers — routers, firewalls, or hosts — and protects the IP packets flowing between them. Before any protected traffic flows, the peers must negotiate a set of security parameters and establish Security Associations (SAs) using the IKE (Internet Key Exchange) protocol.
Without IPsec (plaintext across the internet):
[PC at HQ] ──── Internet ────────────────────── [Server at Branch]
Anyone on path can read/modify packets
With IPsec site-to-site tunnel:
[PC at HQ]──[Router A]═══[ENCRYPTED TUNNEL]═══[Router B]──[Server at Branch]
192.168.1.0/24 Internet 192.168.2.0/24
Traffic is encrypted between Router A and Router B;
PCs and servers need no special configuration
IPsec delivers three core security services:
| Service | Mechanism | What It Prevents |
|---|---|---|
| Confidentiality | Symmetric encryption (AES, 3DES) | Eavesdropping — attacker cannot read intercepted packets |
| Integrity | HMAC (SHA-256, SHA-384) | Tampering — any modification to a packet is detected and the packet is discarded |
| Authentication | Pre-shared keys or digital certificates | Impersonation — verifies the remote peer is who it claims to be |
| Anti-Replay | Sequence numbers in ESP/AH headers | Replay attacks — attacker cannot capture and re-send valid encrypted packets to trick the receiver |
Related pages: IPsec VPN | Site-to-Site vs Remote-Access VPN | AAA Authentication Methods | AAA Overview | NAT Overview | ACL Overview | Applying ACLs | SSH Configuration | Site-to-Site IPsec VPN Lab | GRE Tunnel Configuration Lab
2. IPsec Protocol Components: AH and ESP
IPsec uses two protocol headers to secure packets. These are applied to the original IP packet either in Transport mode or Tunnel mode (covered in Section 3).
Authentication Header (AH) — Protocol 51
AH provides integrity, source authentication, and anti-replay protection for the entire IP packet — including the original IP header. It does not provide encryption. AH is identified by IP Protocol Number 51.
AH in Transport Mode:
┌───────────┬──────────┬─────────────────┐
│ IP Header │ AH Header│ Original Payload │
└───────────┴──────────┴─────────────────┘
↑ Integrity check covers HMAC over IP header + payload
↑ No encryption — payload is still readable
Encapsulating Security Payload (ESP) — Protocol 50
ESP provides confidentiality (encryption), integrity, source authentication, and anti-replay. It is the most widely used IPsec component and is standard in all modern VPN deployments. ESP is identified by IP Protocol Number 50.
ESP in Tunnel Mode (site-to-site VPN — most common):
┌──────────────┬────────────┬────────────────┬─────────────────────────────┬───────────┬──────────┐
│ New IP Header│ ESP Header │ Original IP Hdr│ Original Payload │ ESP Trailer│ ESP Auth │
└──────────────┴────────────┴─────────────────────────────────────────────┴───────────┴──────────┘
←─────────────────── ENCRYPTED ──────────────────────────→
←────────────── INTEGRITY CHECK ───────────────────→
ESP Header contains: SPI (32 bits) | Sequence Number (32 bits)
ESP Trailer contains: Padding | Pad Length | Next Header
ESP Auth: HMAC value over ESP Header + Encrypted data + ESP Trailer
AH vs ESP — Full Comparison
| Feature | AH (Protocol 51) | ESP (Protocol 50) |
|---|---|---|
| Encryption (Confidentiality) | No — payload remains readable | Yes — payload is encrypted |
| Integrity | Yes — covers entire packet including IP header | Yes — covers ESP header + payload + trailer |
| Source Authentication | Yes | Yes (optional — ESP-auth) |
| Anti-Replay | Yes | Yes |
| IP header integrity | Yes — covers original IP header fields | No — new outer IP header not covered by integrity |
| NAT compatibility | Breaks with NAT — NAT changes IP header, invalidating AH integrity check | Compatible with NAT-T (UDP encapsulation) |
| IP Protocol Number | 51 | 50 |
| Deployment | Rare — legacy, used when encryption prohibited by policy but authentication required | Universal — standard for all VPN deployments |
3. IPsec Modes: Transport vs Tunnel
IPsec can operate in two modes that determine which part of the original packet is protected and whether a new IP header is added.
Transport Mode
Original packet: ┌───────────┬────────────────────────────────┐ │ IP Header │ TCP/UDP Header + Payload │ │ (src/dst) │ │ └───────────┴────────────────────────────────┘ After ESP Transport Mode: ┌───────────┬────────────┬────────────────────────────────┬───────────┬──────────┐ │ IP Header │ ESP Header │ TCP/UDP Header + Payload (ENC) │ ESP Trail │ ESP Auth │ │(unchanged)│ │ │ │ │ └───────────┴────────────┴────────────────────────────────┴───────────┴──────────┘ The original IP header is preserved — src/dst IPs are the actual host IPs Only the upper-layer payload (TCP/UDP + data) is encrypted
- What is protected: Upper-layer payload (TCP/UDP header + data) only
- IP header: Original IP header unchanged — source and destination IPs are visible to anyone on the path
- Use case: Host-to-host communication where both endpoints are IPsec-capable (e.g., server-to-server database replication, Microsoft L2TP/IPsec client VPN inner encryption)
- Overhead: Lower — no new IP header added
Tunnel Mode
Original packet:
┌───────────┬────────────────────────────────┐
│ IP Header │ TCP/UDP Header + Payload │
│192.168.1.10→192.168.2.10 │
└───────────┴────────────────────────────────┘
After ESP Tunnel Mode:
┌──────────────┬────────────┬──────────────────────────────────────────┬──────────┐
│ New IP Header│ ESP Header │ [Original IP Hdr + TCP/UDP + Payload ENC]│ ESP Auth │
│198.51.100.1 → 203.0.113.1│ │ │
└──────────────┴────────────┴──────────────────────────────────────────┴──────────┘
↑ Outer header = VPN gateway IPs (visible)
↑ Entire original packet = encrypted (hidden inside tunnel)
- What is protected: Entire original IP packet — header and payload
- IP header: New outer IP header added with VPN gateway addresses; original src/dst IPs are hidden inside the encrypted payload
- Use case: Site-to-site VPNs (gateway-to-gateway), remote-access VPNs — the default and overwhelmingly dominant IPsec mode
- Overhead: Higher — new IP header + ESP headers add ~50–60 bytes per packet
| Feature | Transport Mode | Tunnel Mode |
|---|---|---|
| What is encrypted | Payload only (TCP/UDP + data) | Entire original packet (IP header + payload) |
| Original IP header visible | Yes — src/dst IPs of actual hosts exposed | No — hidden inside encrypted envelope |
| New IP header added | No | Yes — outer header with VPN gateway IPs |
| Typical use | Host-to-host (both ends IPsec-aware) | Site-to-site VPN, remote-access VPN (default) |
| Header overhead | Lower | Higher (~20 bytes extra for new IP header) |
4. Security Associations (SA) and the SAD
A Security Association (SA) is a one-directional logical relationship between two IPsec peers that defines all the parameters needed to protect traffic in that direction. Because an SA is unidirectional, two SAs are needed for bidirectional communication (one for each direction).
Each SA contains:
- SPI (Security Parameter Index): A 32-bit value in the ESP/AH header that uniquely identifies the SA. The receiving peer uses the SPI to look up the correct SA in the Security Association Database (SAD).
- Destination IP: The endpoint this SA applies to
- IPsec protocol: AH or ESP
- Encryption algorithm and key: e.g., AES-256 + 256-bit key
- Integrity algorithm and key: e.g., HMAC-SHA-256 + key
- Mode: Transport or Tunnel
- SA lifetime: In seconds or bytes — SA is re-keyed when lifetime expires
- Sequence number: Current anti-replay counter
For an IPsec tunnel between Router A and Router B: SA #1 (Inbound to Router A, Outbound from Router B): SPI=0xABC123, ESP, AES-256, HMAC-SHA256, Tunnel mode, lifetime=3600s SA #2 (Outbound from Router A, Inbound to Router B): SPI=0xDEF456, ESP, AES-256, HMAC-SHA256, Tunnel mode, lifetime=3600s Each SA is stored in the Security Association Database (SAD) Router A's SAD: Two entries — one inbound, one outbound Router B's SAD: Two entries — mirror of Router A's SAD
5. IKE — Internet Key Exchange
IKE (Internet Key Exchange) is the protocol that automatically negotiates and manages IPsec Security Associations. Without IKE, both peers would need to manually configure identical encryption keys — unscalable and insecure for large networks. IKE runs over UDP port 500 (and UDP 4500 when NAT-T is active).
IKE operates in two phases:
IKE Phase 1 — Building the Management Channel (ISAKMP SA)
Phase 1 establishes a secure, authenticated channel between the two peers — the ISAKMP SA (Internet Security Association and Key Management Protocol). This management channel is then used to safely negotiate the actual IPsec SAs in Phase 2.
Phase 1 negotiation (IKEv1 Main Mode — 6 messages):
Peer A Peer B
│── Message 1: Propose ISAKMP policy ──▶ │ (encryption, hash, auth, DH group, lifetime)
│◀─ Message 2: Accept/Reject policy ── │
│── Message 3: DH public key + nonce ──▶ │ (start Diffie-Hellman exchange)
│◀─ Message 4: DH public key + nonce ── │
│ │
[Both sides independently compute shared secret using DH]
[Session keys derived from: DH secret + nonces]
│ │
│── Message 5: Auth payload (encrypted) ▶ │ (pre-shared key or digital cert)
│◀─ Message 6: Auth payload (encrypted) ─ │
│ │
ISAKMP SA established (Phase 1 complete)
Purpose: Protects Phase 2 negotiation
Lifetime: Typically 86400 seconds (24 hours)
Phase 1 parameters negotiated (must match exactly on both peers):
| Parameter | What It Defines | Recommended Value | Legacy (Avoid) |
|---|---|---|---|
| Encryption | Algorithm for protecting Phase 1 messages | AES-256 | DES, 3DES |
| Hash / Integrity | HMAC algorithm for message integrity | SHA-256, SHA-384 | MD5, SHA-1 |
| Authentication | How peers prove identity | Digital certificates (RSA/ECDSA) | Pre-shared key (PSK) — simpler but less scalable |
| DH Group | Diffie-Hellman group for key exchange | Group 14 (2048-bit) or higher; Groups 19/20 (ECDH) | Group 1 (768-bit), Group 2 (1024-bit) — deprecated |
| Lifetime | How long Phase 1 SA is valid before re-keying | 86400 seconds (24 hours) | Very short lifetimes increase re-keying overhead |
IKE Phase 2 — Negotiating the IPsec SAs (Quick Mode)
Phase 2 uses the secure channel established in Phase 1 to negotiate the actual IPsec SAs that will protect the data traffic. This is called Quick Mode in IKEv1 and completes in 3 messages.
Phase 2 (Quick Mode — 3 messages, protected by Phase 1 ISAKMP SA):
Peer A Peer B
│── Propose IPsec SA parameters ───────▶ │ (ESP/AH, encryption, hash, lifetime,
│ │ traffic selectors/ACL, PFS DH group)
│◀─ Accept parameters ──────────────── │
│── Confirm ──────────────────────────▶ │
│ │
IPsec SAs established (two — one per direction)
Purpose: Protects actual user data traffic
Lifetime: Typically 3600 seconds (1 hour) and/or data volume limit
Phase 2 parameters negotiated:
| Parameter | What It Defines | Example |
|---|---|---|
| IPsec Protocol | AH or ESP | ESP (virtually universal) |
| Encryption | Algorithm for encrypting user data | AES-256-GCM (authenticated encryption — no separate hash needed) |
| Integrity (Hash) | HMAC for data integrity | SHA-256 (with non-GCM cipher suites) |
| Mode | Transport or Tunnel | Tunnel (site-to-site VPN default) |
| Traffic Selectors | Which traffic to encrypt (ACL) | 192.168.1.0/24 ↔ 192.168.2.0/24 |
| PFS (DH Group) | New DH exchange for each Phase 2 SA (optional) | Group 14 or Group 20 (ECDH) |
| Lifetime | How long IPsec SAs are valid | 3600 seconds (1 hour) — shorter than Phase 1 |
6. IKEv1 vs IKEv2
| Feature | IKEv1 | IKEv2 |
|---|---|---|
| RFC | RFC 2409 (1998) | RFC 7296 (2014) |
| Phase 1 messages | 6 (Main Mode) or 3 (Aggressive Mode) | 4 (combined into single exchange — IKE_SA_INIT + IKE_AUTH) |
| Message exchanges | Phase 1 + Phase 2 (separate, sequential) | Single unified exchange — faster and simpler |
| NAT Traversal | Requires separate NAT-T extension (RFC 3947) | Built-in — automatic detection and handling |
| EAP authentication | Not supported | Supported — enables remote-access VPN with username/password |
| Dead Peer Detection (DPD) | Extension (RFC 3706) | Built-in liveness check |
| MOBIKE (mobility) | Not supported | Supported — VPN survives IP address change (mobile clients) |
| Cisco IOS command | crypto isakmp policy |
crypto ikev2 proposal |
| Recommended? | Legacy — still widely deployed | Yes — preferred for all new deployments |
7. Diffie-Hellman Key Exchange and Perfect Forward Secrecy
Diffie-Hellman (DH) Key Exchange
Diffie-Hellman is the mathematical mechanism that allows two peers to independently derive the same shared secret key over an untrusted channel — without ever transmitting the key itself. IPsec uses DH during Phase 1 (and optionally Phase 2 with PFS) to generate the keying material.
Diffie-Hellman — simplified: Peer A and Peer B agree publicly on DH group parameters (prime p, generator g) Peer A: generates secret a → computes public value A = g^a mod p → sends A Peer B: generates secret b → computes public value B = g^b mod p → sends B Peer A: computes shared secret = B^a mod p = g^(ab) mod p Peer B: computes shared secret = A^b mod p = g^(ab) mod p Both arrive at the same shared secret without ever transmitting it An interceptor who captured A and B cannot compute g^(ab) mod p without solving the Discrete Logarithm Problem (computationally infeasible with large groups)
DH Group Recommendations
| DH Group | Key Size / Type | Status | Recommendation |
|---|---|---|---|
| Group 1 | 768-bit MODP | Deprecated | Never use — trivially broken |
| Group 2 | 1024-bit MODP | Deprecated | Avoid — vulnerable to nation-state attacks; still common in legacy config |
| Group 5 | 1536-bit MODP | Deprecated | Avoid — marginal improvement over Group 2 |
| Group 14 | 2048-bit MODP | Acceptable | Minimum acceptable for new deployments; widely supported |
| Group 19 | 256-bit ECDH (P-256) | Recommended | Smaller key, same security as 3072-bit MODP; efficient |
| Group 20 | 384-bit ECDH (P-384) | Recommended | Higher security; used in NSA Suite B / CNSA compliance |
Perfect Forward Secrecy (PFS)
PFS ensures that if a long-term key (the Phase 1 Diffie-Hellman key) is ever compromised, past Phase 2 session keys cannot be derived from it. Without PFS, all Phase 2 SAs use keying material derived from the Phase 1 DH exchange — compromise of Phase 1 material could retroactively decrypt past IPsec traffic.
With PFS enabled, each Phase 2 negotiation performs a fresh independent DH exchange. Each session's encryption keys are derived from this new, ephemeral DH secret. Compromising one session's keys reveals nothing about any other session.
8. NAT Traversal (NAT-T)
NAT-T (NAT Traversal) solves the fundamental incompatibility between IPsec ESP and NAT devices. The problem: ESP is a Layer 3 protocol — it has no port numbers. A NAT device that performs PAT (Port Address Translation) works by tracking connections using source port numbers. Since ESP has no ports, PAT-based NAT cannot correctly demultiplex ESP packets to the right internal host. Additionally, NAT modifies the outer IP source address, which can interfere with IPsec integrity checking.
Problem without NAT-T: Internal PC ──── Router A (behind NAT) ──── Internet ──── Router B 192.168.1.1 10.0.0.1/1.2.3.4 5.6.7.8 Router A sends ESP packet: src=10.0.0.1, proto=50 (ESP) NAT rewrites: src=1.2.3.4, proto=50 (ESP) Router B receives: src=1.2.3.4, proto=50 → processes fine (outbound OK) Router B sends ESP reply: dst=1.2.3.4, proto=50 NAT at Router A sees: dst=1.2.3.4, proto=50 (no port!) NAT cannot determine which internal host this belongs to → DROPS packet Solution — NAT-T: ┌─────────────────────────────────────────────────────────────────┐ │ Outer IP Header │ UDP Header (src/dst port 4500) │ ESP Packet │ └─────────────────────────────────────────────────────────────────┘ NAT can now track by UDP port 4500 → correctly demultiplexes Both peers detected NAT during IKE negotiation (IKE NAT-D payloads) and automatically switched to UDP 4500 encapsulation
Key NAT-T details:
- IKE negotiation still starts on UDP 500 — NAT is detected during Phase 1 using NAT-D (NAT Discovery) payloads
- If NAT is detected, both peers switch to UDP 4500 for the remainder of IKE and all ESP traffic
- IKEv2 has NAT-T built in natively; IKEv1 requires the RFC 3947 extension
- Firewalls must allow UDP 500 and UDP 4500 (and optionally protocol 50 ESP if NAT-T is not needed) for IPsec to function
9. Cisco IOS IPsec Site-to-Site VPN Configuration
Complete configuration example for a site-to-site IPsec VPN using IKEv1 (ISAKMP) on Cisco IOS.
Topology: HQ Router A Branch Router B LAN: 192.168.1.0/24 LAN: 192.168.2.0/24 Public IP: 198.51.100.1 Public IP: 203.0.113.1 Outside IF: GigabitEthernet0/0 Outside IF: GigabitEthernet0/0 Inside IF: GigabitEthernet0/1 Inside IF: GigabitEthernet0/1
Step 1 — Define Interesting Traffic (ACL)
! On BOTH routers (mirrored — what is src on one is dst on the other) ! Router A: access-list 100 permit ip 192.168.1.0 0.0.0.255 192.168.2.0 0.0.0.255 ! Router B: access-list 100 permit ip 192.168.2.0 0.0.0.255 192.168.1.0 0.0.0.255
Step 2 — Configure IKE Phase 1 Policy (ISAKMP)
! On BOTH routers (parameters must match exactly): crypto isakmp policy 10 encr aes 256 ! Encryption: AES-256 hash sha256 ! Integrity: SHA-256 authentication pre-share ! Authentication: pre-shared key group 14 ! DH Group: 2048-bit (minimum recommended) lifetime 86400 ! SA lifetime: 24 hours (seconds)
Step 3 — Set the Pre-Shared Key
! Router A — key for peer Router B's public IP: crypto isakmp key Sup3rS3cr3tK3y address 203.0.113.1 ! Router B — key for peer Router A's public IP: crypto isakmp key Sup3rS3cr3tK3y address 198.51.100.1 ! Keys must be IDENTICAL on both sides
Step 4 — Define the IPsec Transform Set (Phase 2)
! On BOTH routers (must match): crypto ipsec transform-set MYSET esp-aes 256 esp-sha256-hmac ! ↑ ESP ↑ AES-256 encryption ↑ SHA-256 integrity mode tunnel ! Tunnel mode (default for site-to-site)
Step 5 — Create the Crypto Map
! Router A: crypto map MYMAP 10 ipsec-isakmp set peer 203.0.113.1 ! Remote peer's public IP set transform-set MYSET ! Reference the transform set from Step 4 match address 100 ! Reference the ACL from Step 1 set pfs group14 ! (Optional) Enable Perfect Forward Secrecy ! Router B: crypto map MYMAP 10 ipsec-isakmp set peer 198.51.100.1 set transform-set MYSET match address 100 set pfs group14
Step 6 — Apply Crypto Map to the Outside Interface
! On BOTH routers — apply to the WAN/outside interface: interface GigabitEthernet0/0 crypto map MYMAP
Step 7 — Exempt VPN Traffic from NAT (if NAT is configured)
! Router A — VPN traffic must NOT be NATed: ! Deny VPN traffic in the NAT ACL (traffic that should NOT be NATed): ip access-list extended NAT_ACL deny ip 192.168.1.0 0.0.0.255 192.168.2.0 0.0.0.255 permit ip 192.168.1.0 0.0.0.255 any ip nat inside source list NAT_ACL interface GigabitEthernet0/0 overload ! The "deny" line ensures 192.168.1.x → 192.168.2.x traffic bypasses NAT
10. Verification Commands
! ── Phase 1 (ISAKMP SA) Status ──────────────────────────────────────────
Router# show crypto isakmp sa
Expected output when tunnel is up:
IPv4 Crypto ISAKMP SA
dst src state conn-id status
203.0.113.1 198.51.100.1 QM_IDLE 1001 ACTIVE
! ↑ QM_IDLE = Phase 1 complete and ready
! ── Phase 2 (IPsec SA) Status ────────────────────────────────────────────
Router# show crypto ipsec sa
Key output to examine:
interface: GigabitEthernet0/0
Crypto map tag: MYMAP, local addr 198.51.100.1
protected vrf: (none)
local ident (addr/mask/prot/port): (192.168.1.0/255.255.255.0/0/0)
remote ident (addr/mask/prot/port): (192.168.2.0/255.255.255.0/0/0)
current_peer 203.0.113.1 port 500
#pkts encaps: 143, #pkts encrypt: 143, #pkts digest: 143
#pkts decaps: 138, #pkts decrypt: 138, #pkts verify: 138
! ↑ Incrementing encaps/decaps = traffic flowing through tunnel
! ── Other Useful Commands ─────────────────────────────────────────────────
show crypto map ! Verify crypto map config
show crypto isakmp policy ! Show Phase 1 policies configured
show crypto ipsec transform-set ! Show transform sets configured
show crypto engine connections active ! Active encryption sessions
show crypto session ! IKEv2 session summary
! ── Debug Commands (use with caution in production) ──────────────────────
debug crypto isakmp ! Phase 1 negotiation in real time
debug crypto ipsec ! Phase 2 negotiation in real time
undebug all ! ALWAYS turn off debugging when done
11. IPsec Packet Flow — End to End
PC at HQ (192.168.1.10) sends packet to PC at Branch (192.168.2.10):
Step 1: PC sends normal IP packet to its default gateway (Router A)
Src: 192.168.1.10, Dst: 192.168.2.10
Step 2: Router A checks routing table → 192.168.2.0/24 reachable via VPN
Router A checks crypto map ACL → matches access-list 100 → PROTECT
Step 3: Router A looks up IPsec SA for this traffic (dst=203.0.113.1)
If SA exists → proceed to Step 4
If no SA → trigger IKE negotiation (Phase 1 + Phase 2) first
Step 4: Router A applies ESP tunnel mode:
- Encrypts original IP packet (AES-256)
- Calculates HMAC-SHA256 over encrypted data
- Adds ESP header (SPI + sequence number) and ESP trailer
- Adds new outer IP header: src=198.51.100.1, dst=203.0.113.1
- Increments sequence number (anti-replay)
Step 5: Encrypted packet transmitted across internet
Outer packet: src=198.51.100.1, dst=203.0.113.1, proto=ESP(50)
Step 6: Router B receives packet, sees proto=50 (ESP)
Looks up SPI from ESP header → finds matching SA in SAD
Verifies HMAC integrity → if mismatch, discard
Checks sequence number → if replay, discard
Decrypts payload → recovers original IP packet
Step 7: Router B forwards original packet to PC at Branch (192.168.2.10)
PC receives packet as if sent directly from 192.168.1.10
12. Troubleshooting IPsec
| Symptom | Likely Cause | Diagnostic & Fix |
|---|---|---|
Phase 1 never establishes (show crypto isakmp sa shows
MM_NO_STATE or empty) |
Mismatched Phase 1 policy (encryption, hash, DH group, lifetime); UDP 500 blocked by firewall; routing problem to peer | Verify Phase 1 parameters match identically on both peers;
confirm UDP 500 is not blocked; ping peer's public IP;
debug crypto isakmp for detailed negotiation |
Phase 1 up but Phase 2 never establishes
(show crypto ipsec sa shows 0 packets) |
Mismatched transform set; mismatched or non-mirrored ACL (interesting traffic); crypto map not applied to interface; PFS group mismatch | Verify transform sets match; verify ACLs are mirrored (HQ src/dst
reversed on branch); confirm crypto map on correct interface;
debug crypto ipsec |
| Tunnel establishes but traffic not flowing (encaps increment, decaps = 0) | Routing issue — traffic not being sent through tunnel; NAT not exempted; ACL on inside interface blocking | Check routing table — is 192.168.2.0/24 pointing toward correct interface? Verify NAT exemption ACL denies VPN traffic before NAT rule |
| Tunnel works from one side only | Asymmetric ACL — ACL on one side does not mirror the other; pre-shared key entered differently on each side | Verify ACL is mirrored; verify PSK is identical (no typos, case-sensitive) |
| IPsec behind NAT not working | NAT-T not supported or disabled; firewall blocking UDP 4500; AH being used instead of ESP | Ensure UDP 4500 is permitted; switch to ESP if AH configured;
IKEv1 requires crypto isakmp nat-traversal command;
IKEv2 handles automatically |
| Tunnel drops periodically and re-establishes | SA lifetime mismatch causing simultaneous re-keying conflict; DPD (Dead Peer Detection) timeout; unstable WAN link | Match SA lifetimes on both peers; ensure DPD timers are appropriate; check WAN stability |
13. IPsec Use Cases
| Use Case | Mode | IKE Version | Description |
|---|---|---|---|
| Site-to-Site VPN | Tunnel (gateway to gateway) | IKEv1 or IKEv2 | Two routers/firewalls create a permanent encrypted tunnel; all traffic between the two LANs is protected automatically; users/PCs need no VPN client |
| Remote-Access VPN | Tunnel (client to gateway) | IKEv2 (preferred), IKEv1 | Individual users run a VPN client (Cisco AnyConnect, native OS IKEv2); tunnel established from user's device to corporate gateway; IKEv2 supports EAP authentication (username/password + cert) |
| Host-to-Host | Transport (end to end) | IKEv2 | Two servers directly establish IPsec; encrypts traffic between specific hosts; used for server-to-server replication, database encryption, or Windows IPsec policies |
| Cloud Connectivity | Tunnel | IKEv2 | On-premises router connects to cloud VPN gateway (AWS VGW, Azure VPN Gateway, GCP Cloud VPN) — extends corporate network into IaaS environments |
14. Key Points & Exam Tips
- IPsec operates at Layer 3 — protects all IP traffic transparently to applications, unlike TLS which is application-layer.
- AH (Protocol 51): Integrity + authentication, NO encryption. Incompatible with NAT. Rarely used. ESP (Protocol 50): Encryption + integrity + authentication. Widely used.
- Transport mode: Protects payload only; original IP header visible. Used for host-to-host. Tunnel mode: Protects entire original packet; new outer IP header added. Used for site-to-site VPN (default).
- IPsec SAs are unidirectional — two SAs needed for bidirectional communication. SPI identifies which SA to use for each packet.
- IKE Phase 1 (ISAKMP SA): Builds secure channel to protect Phase 2. Parameters: encryption, hash, auth, DH group, lifetime. IKE Phase 2 (IPsec SA): Negotiates actual data protection. Parameters: ESP/AH, encryption, hash, mode, traffic selectors, PFS.
- Phase 1 and Phase 2 parameters must match exactly on both peers — any mismatch causes negotiation failure.
- IKEv2 is faster (4 messages vs 9), has built-in NAT-T, supports EAP, and is preferred for all new deployments.
- DH Group 2 (1024-bit) is deprecated — use Group 14 (2048-bit) minimum; Groups 19/20 (ECDH) preferred.
- PFS performs a new DH exchange for each Phase 2 SA — compromise of one session's keys does not reveal other sessions' keys.
- NAT-T encapsulates ESP in UDP port 4500 — required when IPsec peers are behind NAT devices. IKE detection on UDP 500; data on UDP 4500.
- Firewall must permit: UDP 500 (IKE), UDP 4500 (NAT-T), Protocol 50 (ESP) if NAT-T not used.
- Verify with:
show crypto isakmp sa(Phase 1),show crypto ipsec sa(Phase 2 + packet counts). - Always configure NAT exemption for VPN traffic when NAT is configured — VPN traffic must be excluded from the NAT ACL.
Related pages: IPsec VPN | Site-to-Site vs Remote-Access VPN | AAA Authentication Methods | AAA Overview | NAT Overview | ACL Overview | Applying ACLs | SSH Configuration | Site-to-Site IPsec VPN Lab | GRE Tunnel Configuration Lab