Protocol 19 of 81Layer 3FrameAssembly v3.1.2
llms-full.txt
ikev2Internet Key Exchange Protocol Version 2

Phase-1 VPN Key Negotiation (peer1 <-> peer2 ikev2 UDP 500)

Default Port / Protocol
UDP 500 -> 500 (NAT-T 4500)
Host Endpoint Rule
Dual-Stack IPv4/IPv6
Wireshark Display Filter
isakmp
Standards & Specs
RFC 7296, RFC 3948
Wire Stack:Ethernet II[802.1Q / QinQ / MPLS]IPv4 / IPv6IKEv2 (UDP 500 -> 500 (NAT-T 4500))

What It Does on the Wire

Before a single esp packet flows, two VPN concentrators argue about crypto proposals over UDP 500. ikev2 scripts sainit <-> auth handshakes and NAT-T dstport 4500 checks.

Internet Key Exchange Version 2 (ikev2, RFC 7296) performs mutual authentication and establishes IPsec Security Associations over UDP 500 -> 500 (or UDP 4500 -> 4500 when NAT-Traversal is detected). Every IKEv2 packet starts with a 28-byte header containing 64-bit Initiator and Responder SPIs (initiatorspi, responderspi), Next Payload type (nextpayload / nextheader), Version 0x20 (2.0), Exchange Type (34..37), Flags (0x08 Initiator, 0x20 Response), Message ID (msgid), and 32-bit total Length.

FrameAssembly encodes valid IKEv2 headers and chained payload structures across all four RFC 7296 exchange modes (sainit, auth, createchildsa, informational).

VPN Concentrator Firewall & NAT-Traversal (UDP 4500) Audits

Test UDP 500 initial sainit negotiation transitioning to srcport 4500 dstport 4500 auth exchanges across enterprise edge firewalls.

Dead Peer Detection (DPD) & Rekey Lifecycle Simulation

Craft informational DPD probes (flags 0x08 -> flags 0x20) and createchildsa rekey exchanges with incrementing msgid values.

Unauthorized VPN / Shadow Tunnel NDR Detection

Generate Zeek/Suricata test captures flagging unexpected outbound IKEv2 SA_INIT handshakes from internal server subnets.

Minimal Quickstart (ikev2_quickstart.frasm)

Hit Preview Packets to compile in-browser and eyeball timestamps + wire byte lengths, or ship it straight to the Playground.

ikev2_quickstart.frasm7 lines
Open in Playground
host initiator { ip 198.51.100.10 }
host responder { ip 203.0.113.20 }
compile {
initiator -> responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 wait 3ms
initiator <- responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 msgid 0
}

What the Compiler Calculates So You Don't Have To

  • Defaults both srcport and dstport to IANA IKE port 500 (avoiding ephemeral 49152 source ports blocked by strict VPN ACLs).
  • Writes the 28-byte RFC 7296 IKEv2 header (Version 0x20, exact 32-bit Length, 64-bit SPIs) and defaults responderspi to 0 on sainit requests.
  • Accepts exchange modes either bare (ikev2 auth) or prefixed (ikev2 exchange auth), and treats nextheader and nextpayload as exact synonyms.
Multi-Frame Lab · Ready to Compile

IKEv2 SA_INIT on UDP 500 Floating to NAT-Traversal UDP 4500 + DPD Check

Traces a complete IKEv2 phase: SA_INIT on UDP 500, NAT-T port float to UDP 4500 for encrypted IKE_AUTH (nextpayload 46), and an INFORMATIONAL Dead Peer Detection exchange.

ikev2_natt_dpd.frasm14 lines
Open in Playground
host branch_fw { ip 198.51.100.15 }
host cloud_vpn { ip 203.0.113.99 }
compile {
// 1. IKE_SA_INIT on UDP 500 -> 500 (Next Payload 33 = Security Association)
branch_fw -> cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0 msgid 0 flags 0x08 nextpayload 33 wait 4ms
branch_fw <- cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 0 flags 0x20 nextpayload 33 wait 4ms
// 2. Float to UDP 4500 for IKE_AUTH (Next Payload 46 = Encrypted & Authenticated SK)
branch_fw -> cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x08 nextpayload 46 wait 5ms
branch_fw <- cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x20 nextpayload 46 wait 50ms
// 3. INFORMATIONAL Dead Peer Detection (DPD) liveness check
branch_fw -> cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x08 nextpayload 46 wait 3ms
branch_fw <- cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x20 nextpayload 46
}
Terminal Commands (FrameAssembly CLI v3.1.2)
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show ikev2_natt_dpd.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly ikev2_natt_dpd.frasm ikev2_natt_dpd.pcap
frameassembly ikev2_natt_dpd.frasm ikev2_natt_dpd.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse ikev2_natt_dpd.pcap ikev2_natt_dpd_edited.frasm

All ikev2 Keywords & Header Options

Every sub-keyword and header option is lowercase [a-z0-9]+ with zero underscores — mix and match them in any order after ikev2:

src_host -> dst_host ikev2 [exchange <sainit|auth|createchildsa|informational> | sainit | auth | createchildsa | informational] [initiatorspi <u64|"hex">] [responderspi <u64|"hex">] [msgid <number>] [flags <0..255>] [nextpayload|nextheader <0..255>]
Keyword / OptionAccepted ValueDefaultEffect on Packet
sainit | auth | createchildsa | informational | exchange <...>RFC 7296 Exchange Type keyword or u8sainit (34)Sets Exchange Type: sainit (34 IKE_SA_INIT), auth (35 IKE_AUTH), createchildsa (36 CREATE_CHILD_SA), informational (37 INFORMATIONAL).
initiatorspi <u64|"hex"> | responderspi <u64|"hex">64-bit integer or hex stringDeterministic initiator SPI; responderspi 0 on sainitPopulates the 8-byte Initiator SPI and 8-byte Responder SPI in the IKEv2 header.
msgid <number>Whole number0Sets the 4-byte IKEv2 Message ID (0 for sainit, 1 for initial auth, incrementing per request/response pair).
flags <0..255>8-bit bitmask0x08 (Initiator)Sets RFC 7296 Flags (0x08 = Initiator I, 0x10 = Version V, 0x20 = Response R; responder replies to initiator typically use 0x20).
nextpayload <0..255> | nextheader <0..255>8-bit IKEv2 Payload Type33 (SA) or 0 (None)Sets the first chained IKEv2 Payload Type (33 SA, 34 KE, 40 Nonce, 46 Encrypted SK, 0 None).

Cross-Layer Wrappers Valid with ikev2

802.1Q VLAN / QinQ / MPLS tags, IPv4/IPv6 QoS & TTL fields, wait gaps, and transport overrides allowed on this protocol

10 options
OptionRange / FormatDefaultEffect on Packet
wait <number><ns|us|ms|s|m>Time gap (ns, us, ms, s, m)10msAdvances the packet timestamp clock after sending this packet and before the next packet (wait 0ns sends back-to-back).
payload "<text>" | hexpayload "<hex>"Quoted text or hex bytes (choose one)OmittedAppends or overrides raw payload bytes ("deadbeef" or "de:ad:be:ef") and updates packet lengths and checksums.
srcmac <mac> | dstmac <mac>Colon, hyphen, or Cisco dot MACHost MAC / RFC multicast MACOverrides the 14-byte Ethernet II source or destination MAC address for this single packet.
vlan <0..4095> [pcp <0..7>] [dei <0|1>]VLAN ID 0..4095, PCP 0..7, DEI 0..1UntaggedWraps the packet in an IEEE 802.1Q VLAN tag (0x8100) with optional 802.1p QoS priority.
qinq <0..4095> [innervlan <0..4095>]Outer S-VLAN 0..4095, Inner C-VLAN 0..4095Untagged (innervlan 1 when qinq is set)Double-tags the packet with outer IEEE 802.1ad S-Tag (0x88a8) plus inner IEEE 802.1Q C-Tag (0x8100).
mpls <0..1048575> [exp|tc <0..7>] [bos <0|1>] [mplsttl <0..255>]Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255Unlabeled (at most 1 mpls tag per packet)Inserts a 32-bit MPLS label header (0x8847) ahead of the Layer 3 header.
ttl <0..255> [dscp <0..63>] [ecn <0..3>]TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3ttl 64, dscp 0, ecn 0Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings.
ipid <0..65535> [df] [mf] [fragoffset <0..8191>]IPv4 ID, DF/MF flags, fragment offset 0..8191ipid 1, flags 0, fragoffset 0Sets IPv4 Identification, Do-Not-Fragment (df), More-Fragments (mf), and fragment offset (ignored over IPv6).
flowlabel <0..1048575>20-bit IPv6 Flow Label (0..1048575)0Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts).
srcport <0..65535> | dstport <0..65535>Port number 0..65535srcport 49152 (remembered), UDP 500 -> 500 (NAT-T 4500)Overrides source or destination port and remembers the port pair automatically on <- replies.

Gotchas & Quick Fixes

Zero Underscores in Exchange Modes

Avoid
a -> b ikev2 sa_init // or create_child_sa
Valid v3.1.2 Syntax
a -> b ikev2 sainit // or createchildsa

Exchange modes follow the strict lowercase alphanumeric rule: sainit, auth, createchildsa, informational.

Set flags 0x20 on Responder Replies

Valid v3.1.2 Syntax
a <- b ikev2 sainit initiatorspi 0x1122 responderspi 0x3344 flags 0x20

On responder replies (<-), setting flags 0x20 sets the RFC 7296 Response (R) bit and clears the Initiator (I) bit so Wireshark labels the packet (Response).

Field Guide 05
VLANs, QinQ, MPLS, Tunnel Soup & Dual-Stack IPv6