Fortinet black logo

Administration Guide

Performing a sniffer trace or packet capture

Performing a sniffer trace or packet capture

When you troubleshoot networks and routing in particular, it helps to look inside the headers of packets to determine if they are traveling the route that you expect them to take. Packet sniffing is also known as network tap, packet capture, or logic analyzing.

caution icon

For FortiGates with NP2, NP4, or NP6 interfaces that are offloading traffic, disable offloading on these interfaces before you perform a trace or it will change the sniffer trace.

Sniffing packets

To perform a sniffer trace in the CLI:

Before you start sniffing packets, you should prepare to capture the output to a file. A large amount of data may scroll by and you will not be able to see it without saving it first. One method is to use a terminal program like puTTY to connect to the FortiGate CLI. Once the packet sniffing count is reached, you can end the session and analyze the output in the file.

The general form of the internal FortiOS packet sniffer command is:

# diagnose sniffer packet <interface_name> <'filter'> <verbose> <count> <tsformat>

To stop the sniffer, type CTRL+C.

<interface_name>

The name of the interface to sniff, such as port1 or internal. This can also be any to sniff all interfaces.

<'filter'>

What to look for in the information the sniffer reads. none indicates no filtering, and all packets are displayed as the other arguments indicate.

The filter must be inside single quotes (‘).

<verbose>

The level of verbosity as one of:

  • 1 - print header of packets

  • 2 - print header and data from IP of packets

  • 3 - print header and data from Ethernet of packets

  • 4 - print header of packets with interface name

<count>

The number of packets the sniffer reads before stopping. If you don't put a number here, the sniffer will run until you stop it with <CTRL+C>.

<tsformat>

The timestamp format.

  • a: absolute UTC time, yyyy-mm-dd hh:mm:ss.ms
  • l: absolute LOCAL time, yyyy-mm-dd hh:mm:ss.ms
  • otherwise: relative to the start of sniffing, ss.ms
Simple sniffing example:
 # diagnose sniffer packet port1 none 1 3. 

This displays the next three packets on the port1 interface using no filtering, and verbose level 1. At this verbosity level, you can see the source IP and port, the destination IP and port, action (such as ack), and sequence numbers.

In the output below, port 443 indicates these are HTTPS packets and that 172.20.120.17 is both sending and receiving traffic.

Head_Office_620b # diagnose sniffer packet port1 none 1 3

interfaces=[port1]

filters=[none]

0.545306 172.20.120.17.52989 -> 172.20.120.141.443: psh 3177924955 ack 1854307757

0.545963 172.20.120.141.443 -> 172.20.120.17.52989: psh 1854307757 ack 3177925808

0.562409 172.20.120.17.52988 -> 172.20.120.141.443: psh 4225311614 ack 3314279933

Using packet capture

To use packet capture, the FortiGate must have a disk. You can enable capture-packet in the firewall policy.

To enable packet capture in the CLI:

config firewall policy edit <id> set capture-packet enable next end

For information about using the packet capture tool in the GUI, see Using the packet capture tool.

Performing a sniffer trace or packet capture

When you troubleshoot networks and routing in particular, it helps to look inside the headers of packets to determine if they are traveling the route that you expect them to take. Packet sniffing is also known as network tap, packet capture, or logic analyzing.

caution icon

For FortiGates with NP2, NP4, or NP6 interfaces that are offloading traffic, disable offloading on these interfaces before you perform a trace or it will change the sniffer trace.

Sniffing packets

To perform a sniffer trace in the CLI:

Before you start sniffing packets, you should prepare to capture the output to a file. A large amount of data may scroll by and you will not be able to see it without saving it first. One method is to use a terminal program like puTTY to connect to the FortiGate CLI. Once the packet sniffing count is reached, you can end the session and analyze the output in the file.

The general form of the internal FortiOS packet sniffer command is:

# diagnose sniffer packet <interface_name> <'filter'> <verbose> <count> <tsformat>

To stop the sniffer, type CTRL+C.

<interface_name>

The name of the interface to sniff, such as port1 or internal. This can also be any to sniff all interfaces.

<'filter'>

What to look for in the information the sniffer reads. none indicates no filtering, and all packets are displayed as the other arguments indicate.

The filter must be inside single quotes (‘).

<verbose>

The level of verbosity as one of:

  • 1 - print header of packets

  • 2 - print header and data from IP of packets

  • 3 - print header and data from Ethernet of packets

  • 4 - print header of packets with interface name

<count>

The number of packets the sniffer reads before stopping. If you don't put a number here, the sniffer will run until you stop it with <CTRL+C>.

<tsformat>

The timestamp format.

  • a: absolute UTC time, yyyy-mm-dd hh:mm:ss.ms
  • l: absolute LOCAL time, yyyy-mm-dd hh:mm:ss.ms
  • otherwise: relative to the start of sniffing, ss.ms
Simple sniffing example:
 # diagnose sniffer packet port1 none 1 3. 

This displays the next three packets on the port1 interface using no filtering, and verbose level 1. At this verbosity level, you can see the source IP and port, the destination IP and port, action (such as ack), and sequence numbers.

In the output below, port 443 indicates these are HTTPS packets and that 172.20.120.17 is both sending and receiving traffic.

Head_Office_620b # diagnose sniffer packet port1 none 1 3

interfaces=[port1]

filters=[none]

0.545306 172.20.120.17.52989 -> 172.20.120.141.443: psh 3177924955 ack 1854307757

0.545963 172.20.120.141.443 -> 172.20.120.17.52989: psh 1854307757 ack 3177925808

0.562409 172.20.120.17.52988 -> 172.20.120.141.443: psh 4225311614 ack 3314279933

Using packet capture

To use packet capture, the FortiGate must have a disk. You can enable capture-packet in the firewall policy.

To enable packet capture in the CLI:

config firewall policy edit <id> set capture-packet enable next end

For information about using the packet capture tool in the GUI, see Using the packet capture tool.