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.
For more information on controlling GUI packet captures in the CLI, see Using the packet capture tool.
|
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
.
|
The name of the interface to sniff, such as |
|
What to look for in the information the sniffer reads. The filter must be inside single quotes (‘). |
|
The level of verbosity as one of:
|
|
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 < |
|
The timestamp format.
|
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 in a firewall policy
FortiGate can capture packets matching a firewall policy. You can enable capture-packet
in the firewall policy.
To use packet capture, the FortiGate must have a disk and logging must be enabled in the firewall policy.
For information about using the packet capture tool in the GUI, see Using the packet capture tool.
To enable packet capture in a policy in the GUI:
-
Go to Policy & Objects > Firewall Policy and click Create New.
-
Enter a name for the policy and configure the required settings.
-
Enable Log Allowed Traffic and select Security Events or All Sessions.
-
Enable Capture Packets.
-
Click OK.
To enable packet capture in a policy in the CLI:
config firewall policy edit <id> set action accept set logtraffic {all | utm} set capture-packet enable next end
To view the packet capture:
-
Go to Log & Report > Forward Traffic and select the log that matches the firewall policy.
-
Select Details > Archived Data and click on the download button.
-
Open the downloaded PCAP file in a packet analyzer tool, such as Wireshark.