Created on
04-18-2022
08:35 AM
Edited on
12-22-2022
11:54 PM
By
Jean-Philippe_P
Description | This article provides information on how to capture IPsec VPN tunnel packets using FortiGate's CLI tool for troubleshooting. |
Scope | FortiGate. |
Solution |
Below are some of the steps that could be used to capture packets when troubleshooting IPsec VPN tunnel issues.
1) Capturing IKE packets when NAT is not used.
# diag sniffer packet <interface name> "host <remote gw> and udp port 500" 6 0 l
6 - Print header and data from ethernet of packets (if available) with intf name. 0 - Unlimited number of packets will be captured. l - Absolute LOCAL time, yyyy-mm-dd hh:mm:ss.ms.
2) Capturing IKE packets when NAT is used.
Capture only IKE traffic in udp/4500 (i.e., exclude ESP-in-UDP traffic):
udp[8:4] represents UDP packet header total of 8 bytes and 4 bytes of spi field.
3) ESP traffic when NAT is not used.
# diagnose sniffer packet <interface name> "host <remote gw> and esp" 6 0 l
4) ESP traffic for specific IPsec SAs when NAT is not used:
This is useful when there are multiple tunnels with the same IP address and when packet capture is needed for a particular tunnel for troubleshooting.
# diag vpn tunnel list
dec: spi=299f9f87 esp=aes key=16 36a2871bd1830bde2bd0a1da9be4520d
(Note: The above output is filtered)
Below is an example: # diag sniff packet port2 "host 200.0.0.2 and esp and (ip[20:4]==0x299f9f87 or ip [20:4]==0x8a351d96)" 6 0 l
Below is the command syntax: # diag sniff packet <interface name> "host <remote gw> and esp and (ip[20:4]==0x<SPI1> or ip [20:4]==0x<SPI2>)" 6 0 l
ip[20:4] represents IP packet header with total of 20 bytes and spi field with 4 bytes.
5) ESP traffic for specific IPsec SAs when NAT is used:
This is useful when there are multiple tunnels with the same IP address and when packet capture is needed for a particular tunnel for troubleshooting. This would be very helpful in Dial-up VPN issues when multiple clients are behind the same edge device and sharing the public IP address.
# diag vpn tunnel list
dec: spi=299f9f85 esp=aes key=16 81085dedbe81883a23fb7e7bbbf6af34
(Note: The above output is filtered)
Below is an example: # diag sniff packet port2 "host 200.0.0.2 and udp port 4500 and (udp[8:4]==0x299f9f85 or udp [8:4]==0xa2330e8e)" 6 0 l
Below is the command syntax: FGT1 (root) # diag sniff packet <interface name> "host <remote gw> and udp port 4500 and (udp[8:4]==0x<SPI1> or udp [8:4]==0x<SPI2>)" 6 0 l |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2025 Fortinet, Inc. All Rights Reserved.