Fortinet Document Library

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:

Version:


Table of Contents

CLI Reference

sniffer

Use this command to perform a packet trace on one or more network interfaces.

Packet capture, also known as sniffing, records some or all of the packets seen by a network interface. By recording packets, you can trace connection states to the exact point at which they fail, which may help you to diagnose some types of problems that are otherwise difficult to detect.

FortiAnalyzer units have a built-in sniffer. Packet capture on FortiAnalyzer units is similar to that of FortiGate units. Packet capture is displayed on the CLI, which you may be able to save to a file for later analysis, depending on your CLI client.

Packet capture output is printed to your CLI display until you stop it by pressing CTRL + C, or until it reaches the number of packets that you have specified to capture.

Packet capture can be very resource intensive. To minimize the performance impact on your FortiAnalyzer unit, use packet capture only during periods of minimal traffic, with a serial console CLI connection rather than a Telnet or SSH CLI connection, and be sure to stop the command when you are finished.

Syntax

diagnose sniffer packet <interface> <filter> <verbose> <count> <Timestamp format>

Variable

Description

<interface>

Type the name of a network interface whose packets you want to capture, such as port1, or type any to capture packets on all network interfaces.

<filter>

Type either none to capture all packets, or type a filter that specifies which protocols and port numbers that you do or do not want to capture, such as 'tcp port 25'. Surround the filter string in quotes.

The filter uses the following syntax:

'[[src|dst] host {<host1_fqdn> | <host1_ipv4>}] [and|or] [[src|dst] host {<host2_fqdn> | <host2_ipv4>}] [and|or] [[arp|ip|gre|esp|udp|tcp] port <port1_int>] [and|or] [[arp|ip|gre|esp|udp|tcp] port <port2_int>]'

To display only the traffic between two hosts, specify the IP addresses of both hosts. To display only forward or only reply packets, indicate which host is the source, and which is the destination.

For example, to display UDP port 1812 traffic between 1.example.com and either 2.example.com or 3.example.com, you would enter:

'udp and port 1812 and src host 1.example.com and dst \( 2.example.com or 2.example.com \)'

<verbose>

Type one of the following numbers indicating the depth of packet headers and payloads to capture:

  • 1: print header of packets (default)
  • 2: print header and data from ip of packets
  • 3: print header and data from ethernet of packets (if available)
  • 4: print header of packets with interface name
  • 5: print header and data from ip of packets with interface name
  • 6: print header and data from ethernet of packets (if available) with intf name

For troubleshooting purposes, Fortinet Technical Support may request the most verbose level (3).

Default: 1

<count>

Type the number of packets to capture before stopping.

If you do not specify a number, the command will continue to capture packets until you press Control  + C.

<Timestamp format>

Type 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

Example

The following example captures the first three packets’ worth of traffic, of any port number or protocol and between any source and destination (a filter of none), that passes through the network interface named port1. The capture uses a low level of verbosity (indicated by 1).

Commands that you would type are highlighted in bold; responses from the Fortinet unit are not in bold.

FortiAnalyzer# diag sniffer packet port1 none 1 3

interfaces=[port1]

filters=[none]

0.918957 192.168.0.1.36701 -> 192.168.0.2.22: ack 2598697710

0.919024 192.168.0.2.22 -> 192.168.0.1.36701: psh 2598697710 ack 2587945850

0.919061 192.168.0.2.22 -> 192.168.0.1.36701: psh 2598697826 ack 2587945850

If you are familiar with the TCP protocol, you may notice that the packets are from the middle of a TCP connection. Because port 22 is used (highlighted above in bold), which is the standard port number for SSH, the packets might be from an SSH session.

Example

The following example captures packets traffic on TCP port 80 (typically HTTP) between two hosts, 192.168.0.1 and 192.168.0.2. The capture uses a low level of verbosity (indicated by 1). Because the filter does not specify either host as the source or destination in the IP header (src or dst), the sniffer captures both forward and reply traffic.

A specific number of packets to capture is not specified. As a result, the packet capture continues until the administrator presses CTRL + C. The sniffer then confirms that five packets were seen by that network interface.

Commands that you would type are highlighted in bold; responses from the Fortinet unit are not in bold.

FortiAnalyzer# diag sniffer packet port1 'host 192.168.0.2 or host 192.168.0.1 and tcp port 80' 1

192.168.0.2.3625 -> 192.168.0.1.80: syn 2057246590

192.168.0.1.80 -> 192.168.0.2.3625: syn 3291168205 ack 2057246591

192.168.0.2.3625 -> 192.168.0.1.80: ack 3291168206

192.168.0.2.3625 -> 192.168.0.1.80: psh 2057246591 ack 3291168206

192.168.0.1.80 -> 192.168.0.2.3625: ack 2057247265

5 packets received by filter

0 packets dropped by kernel

Example

The following example captures all TCP port 443 (typically HTTPS) traffic occurring through port1, regardless of its source or destination IP address. The capture uses a high level of verbosity (indicated by 3).

A specific number of packets to capture is not specified. As a result, the packet capture continues until the administrator presses CTRL + C. The sniffer then confirms that five packets were seen by that network interface.

Verbose output can be very long. As a result, output shown below is truncated after only one packet.

Commands that you would type are highlighted in bold; responses from the Fortinet unit are not in bold.

FortiAnalyzer # diag sniffer port1 'tcp port 443' 3

interfaces=[port1]

filters=[tcp port 443]

10.651905 192.168.0.1.50242 -> 192.168.0.2.443: syn 761714898

0x0000 0009 0f09 0001 0009 0f89 2914 0800 4500 ..........)...E.

0x0010 003c 73d1 4000 4006 3bc6 d157 fede ac16 .<s.@.@.;..W....

0x0020 0ed8 c442 01bb 2d66 d8d2 0000 0000 a002 ...B..-f........

0x0030 16d0 4f72 0000 0204 05b4 0402 080a 03ab ..Or............

0x0040 86bb 0000 0000 0103 0303 ..........

Instead of reading packet capture output directly in your CLI display, you usually should save the output to a plain text file using your CLI client. Saving the output provides several advantages. Packets can arrive more rapidly than you may be able to read them in the buffer of your CLI display, and many protocols transfer data using encodings other than US-ASCII. It is usually preferable to analyze the output by loading it into in a network protocol analyzer application such as Wireshark (http://www.wireshark.org/).

For example, you could use PuTTY or Microsoft HyperTerminal to save the sniffer output. Methods may vary. See the documentation for your CLI client.

Requirements
  • terminal emulation software such as PuTTY
  • a plain text editor such as Notepad
  • a Perl interpreter
  • network protocol analyzer software such as Wireshark
To view packet capture output using PuTTY and Wireshark:
  1. On your management computer, start PuTTY.
  2. Use PuTTY to connect to the Fortinet appliance using either a local serial console, SSH, or Telnet connection.
  3. Type the packet capture command, such as:

    diagnose sniffer packet port1 'tcp port 541' 3 100

    but do not press Enter yet.

  4. In the upper left corner of the window, click the PuTTY icon to open its drop-down menu, then select Change Settings.

    A dialog appears where you can configure PuTTY to save output to a plain text file.

  5. In the Category tree on the left, go to Session > Logging.
  6. In Session logging, select Printable output.
  7. In Log file name, click the Browse button, then choose a directory path and file name such as C:\Users\MyAccount\packet_capture.txt to save the packet capture to a plain text file. (You do not need to save it with the .log file extension.)
  8. Click Apply.
  9. Press Enter to send the CLI command to the FortiMail unit, beginning packet capture.
  10. If you have not specified a number of packets to capture, when you have captured all packets that you want to analyze, press CTRL + C to stop the capture.
  11. Close the PuTTY window.
  12. Open the packet capture file using a plain text editor such as Notepad++.
  13. Delete the first and last lines, which look like this:

    =~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2019-03-29.07.25 11:34:40 =~=~=~=~=~=~=~=~=~=~=~=

    Fortinet-2000 #

    These lines are a PuTTY timestamp and a command prompt, which are not part of the packet capture. If you do not delete them, they could interfere with the script in the next step.

  14. Convert the plain text file to a format recognizable by your network protocol analyzer application.

    You can convert the plain text file to a format (.pcap) recognizable by Wireshark using the fgt2eth.pl Perl script. To download fgt2eth.pl, see the Fortinet Knowledge Base article Using the FortiOS built-in packet sniffer.

    The fgt2eth.pl script is provided as-is, without any implied warranty or technical support, and requires that you first install a Perl module compatible with your operating system.

    To use fgt2eth.pl, open a command prompt, then enter a command such as the following:

    fgt2eth.pl -in packet_capture.txt -out packet_capture.pcap

    where:

    • fgt2eth.pl is the name of the conversion script; include the path relative to the current directory, which is indicated by the command prompt
    • packet_capture.txt is the name of the packet capture’s output file; include the directory path relative to your current directory
    • packet_capture.pcap is the name of the conversion script’s output file; include the directory path relative to your current directory where you want the converted output to be saved
  15. Open the converted file in your network protocol analyzer application. For further instructions, see the documentation for that application.

    For additional information on packet capture, see the Fortinet Knowledge Base article Using the FortiOS built-in packet sniffer.

sniffer

Use this command to perform a packet trace on one or more network interfaces.

Packet capture, also known as sniffing, records some or all of the packets seen by a network interface. By recording packets, you can trace connection states to the exact point at which they fail, which may help you to diagnose some types of problems that are otherwise difficult to detect.

FortiAnalyzer units have a built-in sniffer. Packet capture on FortiAnalyzer units is similar to that of FortiGate units. Packet capture is displayed on the CLI, which you may be able to save to a file for later analysis, depending on your CLI client.

Packet capture output is printed to your CLI display until you stop it by pressing CTRL + C, or until it reaches the number of packets that you have specified to capture.

Packet capture can be very resource intensive. To minimize the performance impact on your FortiAnalyzer unit, use packet capture only during periods of minimal traffic, with a serial console CLI connection rather than a Telnet or SSH CLI connection, and be sure to stop the command when you are finished.

Syntax

diagnose sniffer packet <interface> <filter> <verbose> <count> <Timestamp format>

Variable

Description

<interface>

Type the name of a network interface whose packets you want to capture, such as port1, or type any to capture packets on all network interfaces.

<filter>

Type either none to capture all packets, or type a filter that specifies which protocols and port numbers that you do or do not want to capture, such as 'tcp port 25'. Surround the filter string in quotes.

The filter uses the following syntax:

'[[src|dst] host {<host1_fqdn> | <host1_ipv4>}] [and|or] [[src|dst] host {<host2_fqdn> | <host2_ipv4>}] [and|or] [[arp|ip|gre|esp|udp|tcp] port <port1_int>] [and|or] [[arp|ip|gre|esp|udp|tcp] port <port2_int>]'

To display only the traffic between two hosts, specify the IP addresses of both hosts. To display only forward or only reply packets, indicate which host is the source, and which is the destination.

For example, to display UDP port 1812 traffic between 1.example.com and either 2.example.com or 3.example.com, you would enter:

'udp and port 1812 and src host 1.example.com and dst \( 2.example.com or 2.example.com \)'

<verbose>

Type one of the following numbers indicating the depth of packet headers and payloads to capture:

  • 1: print header of packets (default)
  • 2: print header and data from ip of packets
  • 3: print header and data from ethernet of packets (if available)
  • 4: print header of packets with interface name
  • 5: print header and data from ip of packets with interface name
  • 6: print header and data from ethernet of packets (if available) with intf name

For troubleshooting purposes, Fortinet Technical Support may request the most verbose level (3).

Default: 1

<count>

Type the number of packets to capture before stopping.

If you do not specify a number, the command will continue to capture packets until you press Control  + C.

<Timestamp format>

Type 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

Example

The following example captures the first three packets’ worth of traffic, of any port number or protocol and between any source and destination (a filter of none), that passes through the network interface named port1. The capture uses a low level of verbosity (indicated by 1).

Commands that you would type are highlighted in bold; responses from the Fortinet unit are not in bold.

FortiAnalyzer# diag sniffer packet port1 none 1 3

interfaces=[port1]

filters=[none]

0.918957 192.168.0.1.36701 -> 192.168.0.2.22: ack 2598697710

0.919024 192.168.0.2.22 -> 192.168.0.1.36701: psh 2598697710 ack 2587945850

0.919061 192.168.0.2.22 -> 192.168.0.1.36701: psh 2598697826 ack 2587945850

If you are familiar with the TCP protocol, you may notice that the packets are from the middle of a TCP connection. Because port 22 is used (highlighted above in bold), which is the standard port number for SSH, the packets might be from an SSH session.

Example

The following example captures packets traffic on TCP port 80 (typically HTTP) between two hosts, 192.168.0.1 and 192.168.0.2. The capture uses a low level of verbosity (indicated by 1). Because the filter does not specify either host as the source or destination in the IP header (src or dst), the sniffer captures both forward and reply traffic.

A specific number of packets to capture is not specified. As a result, the packet capture continues until the administrator presses CTRL + C. The sniffer then confirms that five packets were seen by that network interface.

Commands that you would type are highlighted in bold; responses from the Fortinet unit are not in bold.

FortiAnalyzer# diag sniffer packet port1 'host 192.168.0.2 or host 192.168.0.1 and tcp port 80' 1

192.168.0.2.3625 -> 192.168.0.1.80: syn 2057246590

192.168.0.1.80 -> 192.168.0.2.3625: syn 3291168205 ack 2057246591

192.168.0.2.3625 -> 192.168.0.1.80: ack 3291168206

192.168.0.2.3625 -> 192.168.0.1.80: psh 2057246591 ack 3291168206

192.168.0.1.80 -> 192.168.0.2.3625: ack 2057247265

5 packets received by filter

0 packets dropped by kernel

Example

The following example captures all TCP port 443 (typically HTTPS) traffic occurring through port1, regardless of its source or destination IP address. The capture uses a high level of verbosity (indicated by 3).

A specific number of packets to capture is not specified. As a result, the packet capture continues until the administrator presses CTRL + C. The sniffer then confirms that five packets were seen by that network interface.

Verbose output can be very long. As a result, output shown below is truncated after only one packet.

Commands that you would type are highlighted in bold; responses from the Fortinet unit are not in bold.

FortiAnalyzer # diag sniffer port1 'tcp port 443' 3

interfaces=[port1]

filters=[tcp port 443]

10.651905 192.168.0.1.50242 -> 192.168.0.2.443: syn 761714898

0x0000 0009 0f09 0001 0009 0f89 2914 0800 4500 ..........)...E.

0x0010 003c 73d1 4000 4006 3bc6 d157 fede ac16 .<s.@.@.;..W....

0x0020 0ed8 c442 01bb 2d66 d8d2 0000 0000 a002 ...B..-f........

0x0030 16d0 4f72 0000 0204 05b4 0402 080a 03ab ..Or............

0x0040 86bb 0000 0000 0103 0303 ..........

Instead of reading packet capture output directly in your CLI display, you usually should save the output to a plain text file using your CLI client. Saving the output provides several advantages. Packets can arrive more rapidly than you may be able to read them in the buffer of your CLI display, and many protocols transfer data using encodings other than US-ASCII. It is usually preferable to analyze the output by loading it into in a network protocol analyzer application such as Wireshark (http://www.wireshark.org/).

For example, you could use PuTTY or Microsoft HyperTerminal to save the sniffer output. Methods may vary. See the documentation for your CLI client.

Requirements
  • terminal emulation software such as PuTTY
  • a plain text editor such as Notepad
  • a Perl interpreter
  • network protocol analyzer software such as Wireshark
To view packet capture output using PuTTY and Wireshark:
  1. On your management computer, start PuTTY.
  2. Use PuTTY to connect to the Fortinet appliance using either a local serial console, SSH, or Telnet connection.
  3. Type the packet capture command, such as:

    diagnose sniffer packet port1 'tcp port 541' 3 100

    but do not press Enter yet.

  4. In the upper left corner of the window, click the PuTTY icon to open its drop-down menu, then select Change Settings.

    A dialog appears where you can configure PuTTY to save output to a plain text file.

  5. In the Category tree on the left, go to Session > Logging.
  6. In Session logging, select Printable output.
  7. In Log file name, click the Browse button, then choose a directory path and file name such as C:\Users\MyAccount\packet_capture.txt to save the packet capture to a plain text file. (You do not need to save it with the .log file extension.)
  8. Click Apply.
  9. Press Enter to send the CLI command to the FortiMail unit, beginning packet capture.
  10. If you have not specified a number of packets to capture, when you have captured all packets that you want to analyze, press CTRL + C to stop the capture.
  11. Close the PuTTY window.
  12. Open the packet capture file using a plain text editor such as Notepad++.
  13. Delete the first and last lines, which look like this:

    =~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2019-03-29.07.25 11:34:40 =~=~=~=~=~=~=~=~=~=~=~=

    Fortinet-2000 #

    These lines are a PuTTY timestamp and a command prompt, which are not part of the packet capture. If you do not delete them, they could interfere with the script in the next step.

  14. Convert the plain text file to a format recognizable by your network protocol analyzer application.

    You can convert the plain text file to a format (.pcap) recognizable by Wireshark using the fgt2eth.pl Perl script. To download fgt2eth.pl, see the Fortinet Knowledge Base article Using the FortiOS built-in packet sniffer.

    The fgt2eth.pl script is provided as-is, without any implied warranty or technical support, and requires that you first install a Perl module compatible with your operating system.

    To use fgt2eth.pl, open a command prompt, then enter a command such as the following:

    fgt2eth.pl -in packet_capture.txt -out packet_capture.pcap

    where:

    • fgt2eth.pl is the name of the conversion script; include the path relative to the current directory, which is indicated by the command prompt
    • packet_capture.txt is the name of the packet capture’s output file; include the directory path relative to your current directory
    • packet_capture.pcap is the name of the conversion script’s output file; include the directory path relative to your current directory where you want the converted output to be saved
  15. Open the converted file in your network protocol analyzer application. For further instructions, see the documentation for that application.

    For additional information on packet capture, see the Fortinet Knowledge Base article Using the FortiOS built-in packet sniffer.