Description | This article illustrates the use of some advanced filters that can assist in troubleshooting network issues. |
Scope | FortiGate. |
Solution |
FortiOS uses libpcap/BPF pcap-filter arguments. For reference see libpcap documentation such as 'PCAP-FILTER(7) MAN PAGE'. Note that only packets handled by the CPU can be captured. Ensure that hardware offload is disabled for the relevant policy or function before capturing.
See below for some examples.
Capturing ARP requests and replies with EtherType 0x0806: ARP requests and replies use EtherType 0x0806. It is possible to filter further using an IP address that is the subject of the ARP message.
Specific ICMP messages: ICMP unreachable messages related to a flow will not typically appear on a packet sniffer filtered by destination IP address. To extend the filter to include all ICMP destination unreachable messages, include an 'or' filter for ICMP type 3. Optionally include an ICMP code.
HUB # diagnose sniffer packet any 'host 10.100.1.1 or (icmp[icmptype] == 3 and icmp[icmpcode] == 4)' 4 1000 l
Fragmented Packets: The following example captures fragmented packets.
diagnose sniffer packet any '(ip[6]&32==32 or ip[7]!=0)' 4 0 l
Third-Party ICMP documents: RFC 792 Internet Control Message Protocol IANA ICMP parameters reference Inbound frames on the specific interface: When sniffing using the 'any' interface, inbound and outbound frames will be marked with 'in' or 'out'. However, the destination MAC address is replaced when sniffing on this interface.
SPOKE-1 # diagnose sniffer packet any 'port 22' 6 2 l 2025-01-10 11:24:44.109786 wan1 in 10.255.144.1.22 -> 10.255.144.29.20912: syn 3631446142 ack 560581362
To verify whether a packet was received or sent on an interface while preserving the MAC address in the capture, start a packet capture using the specific interface to capture the keyword 'inbound' or 'outbound'. Note the capture will show only inbound or outbound packets, not the complete flow.
SPOKE-1 # diagnose sniffer packet wan1 'port 22 and inbound' 6 1 l
Packet sniffer output can be passed to the grep command using the pipe '|' character. When used in this way, the capture filter determines which packets will be captured, but only lines matching the grep filter will be output. HUB # diagnose sniffer packet any 'esp' 4 1000 l | grep "spi=0xa5638e7e"
Custom locations within a datagram can be accessed using (proto[offset:size]==0x<hexadecimal value>). Size of location checked can be 1, 2, or 4 bytes.
'ether[0:4]=0x00090f89' <--- first 4 bytes of ethernet header '(ether[0:4]=0x00090f89) and (ether[4:2]=0x10ea)' <-- first 6 bytes of ethernet header, ie the destination MAC address.
Bytes checked can be within the datagram header or body. For example, the IPv4 source address exists in bytes 13-16 of the IPv4 packet. If the size of the Ethernet header is known, ether[] can be used to match IPv4 source address by adding 12 bytes of offset, even though IP address is not part of the Ethernet protocol.
Untagged: 14 bytes, IPv4 source address at ether[26:4] 802.1Q: 18 bytes, IPv4 source address at ether[30:4] 802.1ad "Q-in-Q": 22 bytes. IPv4 source address at ether[34:4]
Example sniffer on wan1 for all untagged packets with the IPv4 source address 10.255.255.100 (hexadecimal value 0x0affff64): diagnose sniffer packet wan1 'ether[26:4]==0x0affff64'
HUB # diagnose sniffer packet port16 'ip[20:4]==0xa5638e7e' 4 2
HUB # diagnose sniffer packet port16 'udp[8:4]==0xe32be0a1' 4 2
See the article 'Technical Tip: Different methods to capture packets for IPsec VPN tunnels troubleshooting' for more details on packet capture for IPsec tunnels including how to find the correct SPI.
Incoming ESP packets for the FortiGate will only be shown if npu-offload was previously disabled for the tunnel under 'config VPN ipsec phase1-interface'.
VNI is a 3-byte value. In a typical Ethernet VXLAN frame, VNI occupies the 47th, 48th, and 49th bytes. To capture traffic based on a specific VNI, convert the decimal VNI into hexadecimal first.
For example, a VNI with the nonstandard decimal value [93] is equivalent to the hexadecimal value [0x5d]
HUB # diagnose sniffer packet LAG_VXLAN '(ether[46:2]=0x0000) and (ether[48:1]=0x5d)' 6 10 l interfaces=[LAG_VXLAN]
Related articles: Troubleshooting Tip: Using the FortiOS built-in packet sniffer for capturing packets |
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.