{"id":184,"date":"2022-11-29T22:40:22","date_gmt":"2022-11-29T21:40:22","guid":{"rendered":"https:\/\/mokrane-assam.com\/?p=184"},"modified":"2026-11-29T22:45:38","modified_gmt":"2026-11-29T21:45:38","slug":"ipsec-basics-esp-ike-phases-and-sas","status":"publish","type":"post","link":"https:\/\/mokrane-assam.com\/index.php\/2022\/11\/29\/ipsec-basics-esp-ike-phases-and-sas\/","title":{"rendered":"IPsec Basics: ESP, IKE Phases, and SAs"},"content":{"rendered":"<p class=\"wp-block-paragraph\">IPsec is the framework that turns the open internet into a private link. It is not one protocol but a kit \u2014 two data-plane protocols, a key-exchange protocol with a life of its own, and a pile of negotiable algorithms. Most IPsec troubleshooting is really one question: which of those negotiations failed? This walk-through goes from the four services IPsec provides to IKEv2, SPIs, and the NAT problem that breaks tunnels in the field.<\/p><h2 class=\"wp-block-heading\">1. The four services, and two ways to deliver them<\/h2><p class=\"wp-block-paragraph\">IPsec provides <strong>confidentiality<\/strong> (encryption), <strong>integrity<\/strong> (the packet was not altered), <strong>authentication<\/strong> (it came from the real peer), and <strong>anti-replay<\/strong> (an attacker cannot resend captured packets). Two protocols carry them: <strong>AH<\/strong> (protocol 51) authenticates but does not encrypt, and <strong>ESP<\/strong> (protocol 50) encrypts and authenticates. In practice everyone uses ESP \u2014 AH&#8217;s lack of encryption and its incompatibility with NAT retired it.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 230\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"IPsec: AH vs ESP\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"230\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">IPsec: AH vs ESP<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"40\" y=\"86\" width=\"400\" height=\"128\" rx=\"10\" fill=\"#fff\" stroke=\"#cbd5e1\"\/><text x=\"240\" y=\"110\" text-anchor=\"middle\" fill=\"#9f1239\" font-size=\"13\" font-weight=\"700\">AH (protocol 51)<\/text><text x=\"240\" y=\"138\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">Integrity + authentication<\/text><text x=\"240\" y=\"160\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">No encryption<\/text><text x=\"240\" y=\"182\" text-anchor=\"middle\" fill=\"#C8102E\" font-size=\"11\">Breaks through NAT \u00b7 rarely used<\/text><rect x=\"480\" y=\"86\" width=\"400\" height=\"128\" rx=\"10\" fill=\"#ecfdf5\" stroke=\"#166534\"\/><text x=\"680\" y=\"110\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"13\" font-weight=\"700\">ESP (protocol 50)<\/text><text x=\"680\" y=\"138\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">Encryption + integrity + auth<\/text><text x=\"680\" y=\"160\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">Anti-replay via sequence numbers<\/text><text x=\"680\" y=\"182\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"11\">The one you actually deploy<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">2. Transport mode vs tunnel mode<\/h2><p class=\"wp-block-paragraph\">IPsec protects a packet in one of two shapes. <strong>Transport mode<\/strong> encrypts only the payload and keeps the original IP header \u2014 host-to-host, where the endpoints are the crypto endpoints. <strong>Tunnel mode<\/strong> wraps the <em>entire<\/em> original packet inside a new IP header \u2014 the shape every site-to-site VPN uses, because the gateways encrypt on behalf of the hosts behind them, hiding the internal addresses.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 230\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"Transport mode vs tunnel mode\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"230\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">Transport mode vs tunnel mode<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><text x=\"240\" y=\"90\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"700\">Transport mode<\/text><rect x=\"60\" y=\"100\" width=\"120\" height=\"40\" rx=\"6\" fill=\"#e0f2fe\" stroke=\"#0A66C2\"\/><text x=\"120\" y=\"124\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"10.5\">IP header<\/text><rect x=\"185\" y=\"100\" width=\"230\" height=\"40\" rx=\"6\" fill=\"#dcfce7\" stroke=\"#166534\"\/><text x=\"300\" y=\"124\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"10.5\">ESP + encrypted payload<\/text><text x=\"240\" y=\"162\" text-anchor=\"middle\" fill=\"#64748b\" font-size=\"10.5\">original IP header kept \u00b7 host-to-host<\/text><text x=\"680\" y=\"90\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"700\">Tunnel mode<\/text><rect x=\"490\" y=\"100\" width=\"110\" height=\"40\" rx=\"6\" fill=\"#fff7ed\" stroke=\"#f59e0b\"\/><text x=\"545\" y=\"124\" text-anchor=\"middle\" fill=\"#9a3412\" font-size=\"10\">NEW IP hdr<\/text><rect x=\"605\" y=\"100\" width=\"275\" height=\"40\" rx=\"6\" fill=\"#dcfce7\" stroke=\"#166534\"\/><text x=\"742\" y=\"118\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"10\">ESP + [original IP hdr + payload]<\/text><text x=\"742\" y=\"133\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"9\">all encrypted<\/text><text x=\"680\" y=\"162\" text-anchor=\"middle\" fill=\"#64748b\" font-size=\"10.5\">whole packet wrapped \u00b7 site-to-site VPN<\/text><text x=\"460\" y=\"200\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"11\">Tunnel mode hides the internal source\/destination; transport mode does not<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">3. IKE builds the tunnel in phases<\/h2><p class=\"wp-block-paragraph\">Before any data is protected, the peers must agree on keys and algorithms \u2014 that is <strong>IKE<\/strong>&#8216;s job, and it runs over UDP 500. IKEv1 does it in two phases: <strong>Phase 1<\/strong> builds a secure management channel (the ISAKMP SA) and <strong>Phase 2<\/strong> negotiates the actual IPsec SAs that protect traffic. IKEv2 collapses this into far fewer messages, but the mental model \u2014 secure the negotiation first, then negotiate the data protection \u2014 is the same.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 230\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"IKE phases\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"230\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">IKE phases<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"120\" y=\"86\" width=\"310\" height=\"54\" rx=\"10\" fill=\"#e0f2fe\" stroke=\"#0A66C2\"\/><text x=\"275\" y=\"108\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"700\">Phase 1 \u2014 ISAKMP SA<\/text><text x=\"275\" y=\"128\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">authenticate peers, build secure channel<\/text><rect x=\"490\" y=\"86\" width=\"310\" height=\"54\" rx=\"10\" fill=\"#dcfce7\" stroke=\"#166534\"\/><text x=\"645\" y=\"108\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"12\" font-weight=\"700\">Phase 2 \u2014 IPsec SA<\/text><text x=\"645\" y=\"128\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"10.5\">negotiate keys\/algorithms for the data<\/text><line x1=\"430\" y1=\"113\" x2=\"490\" y2=\"113\" stroke=\"#0A66C2\" stroke-width=\"2\" marker-end=\"url(#ar)\"\/><text x=\"460\" y=\"170\" text-anchor=\"middle\" fill=\"#64748b\" font-size=\"11\">IKEv1: main mode (6 msgs) or aggressive (3) + quick mode (3). IKEv2: 4 messages total.<\/text><text x=\"460\" y=\"198\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"11\">Secure the negotiation channel first, then negotiate the data protection<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">4. Phase 1 \u2014 Diffie-Hellman and peer authentication<\/h2><p class=\"wp-block-paragraph\">Phase 1 solves the hardest problem: agreeing on a secret key over a line an attacker is watching. <strong>Diffie-Hellman<\/strong> lets both sides derive a shared key by exchanging only public values \u2014 the eavesdropper sees the exchange but cannot compute the key. The <strong>DH group<\/strong> sets its strength. The peers then prove who they are with a <strong>pre-shared key<\/strong> or <strong>certificates<\/strong>; a PSK mismatch is the single most common Phase 1 failure.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 220\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"Diffie-Hellman key exchange\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"220\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">Diffie-Hellman key exchange<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"80\" y=\"100\" width=\"180\" height=\"56\" rx=\"10\" fill=\"#fff\" stroke=\"#0A66C2\"\/><text x=\"170\" y=\"132\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"600\">Peer A<\/text><rect x=\"660\" y=\"100\" width=\"180\" height=\"56\" rx=\"10\" fill=\"#fff\" stroke=\"#0A66C2\"\/><text x=\"750\" y=\"132\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"600\">Peer B<\/text><line x1=\"260\" y1=\"118\" x2=\"660\" y2=\"118\" stroke=\"#0A66C2\" stroke-width=\"2\" marker-end=\"url(#ar)\"\/><text x=\"460\" y=\"110\" text-anchor=\"middle\" fill=\"#0A66C2\" font-size=\"10.5\">public value A<\/text><line x1=\"660\" y1=\"140\" x2=\"260\" y2=\"140\" stroke=\"#0A66C2\" stroke-width=\"2\" marker-end=\"url(#ar)\"\/><text x=\"460\" y=\"157\" text-anchor=\"middle\" fill=\"#0A66C2\" font-size=\"10.5\">public value B<\/text><rect x=\"330\" y=\"176\" width=\"260\" height=\"30\" rx=\"6\" fill=\"#dcfce7\" stroke=\"#166534\"\/><text x=\"460\" y=\"196\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"11\" font-weight=\"600\">both derive the SAME shared key<\/text><text x=\"170\" y=\"180\" text-anchor=\"middle\" fill=\"#64748b\" font-size=\"10\">auth: PSK or cert<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">5. Security Associations and the SPI<\/h2><p class=\"wp-block-paragraph\">The negotiated result is a <strong>Security Association (SA)<\/strong> \u2014 a bundle of keys, algorithms, and lifetime. A crucial detail: IPsec SAs are <strong>unidirectional<\/strong>, so every tunnel has at least two, one per direction. Each is identified by a <strong>Security Parameter Index (SPI)<\/strong> carried in the packet, which tells the receiver which SA \u2014 which key set \u2014 to use to decrypt. When you read <code>show crypto<\/code> output, you are reading SAs and SPIs.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 210\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"Security Associations and SPI\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"210\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">Security Associations and SPI<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"120\" y=\"95\" width=\"200\" height=\"56\" rx=\"10\" fill=\"#fff\" stroke=\"#0A66C2\"\/><text x=\"220\" y=\"127\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"600\">Gateway A<\/text><rect x=\"600\" y=\"95\" width=\"200\" height=\"56\" rx=\"10\" fill=\"#fff\" stroke=\"#0A66C2\"\/><text x=\"700\" y=\"127\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"12\" font-weight=\"600\">Gateway B<\/text><line x1=\"320\" y1=\"113\" x2=\"600\" y2=\"113\" stroke=\"#166534\" stroke-width=\"2\" marker-end=\"url(#ar)\"\/><text x=\"460\" y=\"105\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"10.5\">SA (SPI 0xA1) A -> B<\/text><line x1=\"600\" y1=\"135\" x2=\"320\" y2=\"135\" stroke=\"#0A66C2\" stroke-width=\"2\" marker-end=\"url(#ar)\"\/><text x=\"460\" y=\"152\" text-anchor=\"middle\" fill=\"#0A66C2\" font-size=\"10.5\">SA (SPI 0xB2) B -> A<\/text><text x=\"460\" y=\"188\" text-anchor=\"middle\" fill=\"#64748b\" font-size=\"11\">SAs are unidirectional; the SPI in each packet selects the key set to decrypt with<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">6. What an ESP packet actually looks like<\/h2><p class=\"wp-block-paragraph\">Seeing the ESP encapsulation makes the rest concrete. ESP adds a header (with the SPI and a sequence number for anti-replay) in front of the protected data, and a trailer plus an authentication value behind it. The original payload \u2014 and in tunnel mode the original IP header too \u2014 sits encrypted in the middle, unreadable without the SA&#8217;s key.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 190\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"ESP packet structure\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"190\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">ESP packet structure<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"60\" y=\"100\" width=\"110\" height=\"46\" rx=\"6\" fill=\"#fff7ed\" stroke=\"#f59e0b\"\/><text x=\"115\" y=\"120\" text-anchor=\"middle\" fill=\"#9a3412\" font-size=\"10\">New IP hdr<\/text><text x=\"115\" y=\"136\" text-anchor=\"middle\" fill=\"#9a3412\" font-size=\"9\">(tunnel)<\/text><rect x=\"175\" y=\"100\" width=\"130\" height=\"46\" rx=\"6\" fill=\"#e0f2fe\" stroke=\"#0A66C2\"\/><text x=\"240\" y=\"120\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"10\">ESP header<\/text><text x=\"240\" y=\"136\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"9\">SPI + seq#<\/text><rect x=\"310\" y=\"100\" width=\"330\" height=\"46\" rx=\"6\" fill=\"#dcfce7\" stroke=\"#166534\"\/><text x=\"475\" y=\"126\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"11\" font-weight=\"600\">encrypted: payload (+ orig IP hdr)<\/text><rect x=\"645\" y=\"100\" width=\"100\" height=\"46\" rx=\"6\" fill=\"#e0f2fe\" stroke=\"#0A66C2\"\/><text x=\"695\" y=\"126\" text-anchor=\"middle\" fill=\"#0f172a\" font-size=\"10\">ESP trailer<\/text><rect x=\"750\" y=\"100\" width=\"110\" height=\"46\" rx=\"6\" fill=\"#eef2ff\" stroke=\"#c7d2fe\"\/><text x=\"805\" y=\"120\" text-anchor=\"middle\" fill=\"#3730a3\" font-size=\"10\">ESP auth<\/text><text x=\"805\" y=\"136\" text-anchor=\"middle\" fill=\"#3730a3\" font-size=\"9\">(ICV)<\/text><text x=\"460\" y=\"176\" text-anchor=\"middle\" fill=\"#64748b\" font-size=\"11\">SPI + sequence number live in the ESP header; the data is encrypted and authenticated<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">7. IKEv2 \u2014 why the newer version wins<\/h2><p class=\"wp-block-paragraph\">IKEv2 is not a tweak; it is a cleaner protocol. It establishes a tunnel in a single four-message exchange instead of IKEv1&#8217;s six-plus-three, so it sets up faster. It builds in <strong>NAT traversal<\/strong>, <strong>dead-peer detection<\/strong>, and <strong>EAP<\/strong> authentication that IKEv1 bolted on awkwardly. It also reliably handles rekeying and asymmetric authentication. For anything new, IKEv2 is the default; IKEv1 lingers only for legacy interoperability.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 210\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"IKEv1 vs IKEv2\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"210\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">IKEv1 vs IKEv2<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"40\" y=\"90\" width=\"400\" height=\"100\" rx=\"10\" fill=\"#fff\" stroke=\"#cbd5e1\"\/><text x=\"240\" y=\"116\" text-anchor=\"middle\" fill=\"#9f1239\" font-size=\"13\" font-weight=\"700\">IKEv1<\/text><text x=\"240\" y=\"140\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">6+3 messages \u00b7 NAT-T, DPD bolted on<\/text><text x=\"240\" y=\"162\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">two separate phases, more round trips<\/text><rect x=\"480\" y=\"90\" width=\"400\" height=\"100\" rx=\"10\" fill=\"#ecfdf5\" stroke=\"#166534\"\/><text x=\"680\" y=\"116\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"13\" font-weight=\"700\">IKEv2<\/text><text x=\"680\" y=\"140\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">4 messages \u00b7 NAT-T, DPD, EAP built in<\/text><text x=\"680\" y=\"162\" text-anchor=\"middle\" fill=\"#334155\" font-size=\"11\">cleaner rekeying, faster setup<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">8. The three things that break tunnels in the field<\/h2><p class=\"wp-block-paragraph\">Three real-world mechanisms cause most production incidents. <strong>NAT-T<\/strong>: ESP has no port numbers, so a NAT device cannot track it; IKEv2 detects NAT and wraps ESP in UDP 4500 so it survives \u2014 if that is blocked, the tunnel builds but no traffic passes. <strong>DPD<\/strong> (dead-peer detection) notices a silently dead peer and tears the SA down instead of blackholing traffic. <strong>PFS<\/strong> (perfect forward secrecy) forces a fresh Diffie-Hellman at each rekey, so compromising one key does not expose past or future sessions \u2014 and a PFS mismatch between peers silently drops rekeys.<\/p><figure class=\"mkz-diagram\" style=\"margin:24px auto;max-width:920px\"><svg style=\"width:100%;height:auto;display:block;margin:0 auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 920 200\" font-family=\"'Segoe UI',Roboto,Helvetica,Arial,sans-serif\" role=\"img\" aria-label=\"NAT-T, DPD, and PFS\"><defs><linearGradient id=\"hg\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#17263f\"\/><stop offset=\"1\" stop-color=\"#0f172a\"\/><\/linearGradient><marker id=\"ar\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0L10 5L0 10z\" fill=\"#0A66C2\"\/><\/marker><\/defs><rect x=\"0\" y=\"0\" width=\"920\" height=\"200\" rx=\"14\" fill=\"#f8fafc\" stroke=\"#e2e8f0\"\/><rect x=\"0\" y=\"0\" width=\"920\" height=\"60\" rx=\"14\" fill=\"url(#hg)\"\/><rect x=\"0\" y=\"40\" width=\"920\" height=\"20\" fill=\"#0f172a\"\/><text x=\"28\" y=\"37\" fill=\"#ffffff\" font-size=\"19\" font-weight=\"700\">NAT-T, DPD, and PFS<\/text><text x=\"892\" y=\"37\" text-anchor=\"end\" fill=\"#38bdf8\" font-size=\"13\" font-weight=\"600\" letter-spacing=\"1\">NET BY ME<\/text><rect x=\"30\" y=\"90\" width=\"270\" height=\"90\" rx=\"10\" fill=\"#fef2f2\" stroke=\"#C8102E\"\/><text x=\"165\" y=\"118\" text-anchor=\"middle\" fill=\"#9f1239\" font-size=\"12\" font-weight=\"700\">NAT-T (UDP 4500)<\/text><text x=\"165\" y=\"140\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">wraps ESP so NAT survives<\/text><text x=\"165\" y=\"158\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">blocked -> tunnel up, no data<\/text><rect x=\"325\" y=\"90\" width=\"270\" height=\"90\" rx=\"10\" fill=\"#fff7ed\" stroke=\"#f59e0b\"\/><text x=\"460\" y=\"118\" text-anchor=\"middle\" fill=\"#9a3412\" font-size=\"12\" font-weight=\"700\">DPD<\/text><text x=\"460\" y=\"140\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">detect a dead peer<\/text><text x=\"460\" y=\"158\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">tear down instead of blackhole<\/text><rect x=\"620\" y=\"90\" width=\"270\" height=\"90\" rx=\"10\" fill=\"#ecfdf5\" stroke=\"#166534\"\/><text x=\"755\" y=\"118\" text-anchor=\"middle\" fill=\"#166534\" font-size=\"12\" font-weight=\"700\">PFS<\/text><text x=\"755\" y=\"140\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">fresh DH at each rekey<\/text><text x=\"755\" y=\"158\" text-anchor=\"middle\" fill=\"#475569\" font-size=\"10.5\">mismatch -> rekeys drop<\/text><\/svg><\/figure><h2 class=\"wp-block-heading\">Takeaways<\/h2><p class=\"wp-block-paragraph\">IPsec is a negotiation wrapped in a negotiation: IKE agrees how to protect the agreement, then agrees how to protect your data, producing unidirectional SAs selected by SPI. Know ESP over AH, tunnel over transport for VPNs, IKEv2 over IKEv1, and the NAT-T\/DPD\/PFS trio \u2014 and the mysterious tunnel that builds but passes no traffic stops being mysterious.<\/p>","protected":false},"excerpt":{"rendered":"<p>IPsec is the framework that turns the open internet into a private link. It is not one protocol but a kit \u2014 two data-plane protocols, a key-exchange protocol with a life of its own, and a pile of negotiable algorithms. Most IPsec troubleshooting is really one question: which of those negotiations failed? This walk-through goes<\/p><\/div>\n<div class=\"blog-btn\"><a href=\"https:\/\/mokrane-assam.com\/index.php\/2022\/11\/29\/ipsec-basics-esp-ike-phases-and-sas\/\" class=\"home-blog-btn\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-basic"],"_links":{"self":[{"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/comments?post=184"}],"version-history":[{"count":1,"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/posts\/184\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/media?parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/categories?post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mokrane-assam.com\/index.php\/wp-json\/wp\/v2\/tags?post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}