Taking a packet trace on Linux using tcpdump

  • 7001152
  • 14-Aug-2008
  • 24-Aug-2016

Environment

Novell SUSE Linux Enterprise Desktop (SLED)
Novell SUSE Linux Enterprise Server (SLES)
Novell Open Enterprise Server 2 (OES 2)
Novell openSUSE

Situation

How to take a packet trace (LAN trace, packet capture) from Linux using tcpdump.

Resolution

tcpdump -i any -s0 -w /tmp/capture.cap
 
-i any = Capture on all interfaces
-s0 = Captures maximum size of packets, without this packets will possibly be truncated.
-w /tmp/capture.cap = Output file for capture

[Please note, this is not an exhaustive list of options, but it covers the basics.  Check the man pages for a complete list]

After capturing the packets is complete, press <Ctrl><c> to stop capturing.

Additional Information

Advanced:
To create a rolling trace, for situation where you are trying to capture a random issue without filling up the partition space, various command options are available.  We recommend the following (these are case-sensitive):
-C file_size (in millions of bytes (1,000,000 bytes, not 1,048,576 bytes).
-W count -- Used in conjunction with -C, this will limit the number of files created to the specified number, overwriting files from the beginning, thus creating a rotating buffer.
 
IE
tcpdump -i <eth device> -s 0 -C <file_size> -W <number of files> -w </path/to/trace.cap>
 
For roughly 9.6 MB files, rotating through three files, the following command is used:
tcpdump -i eth0 -s 0 -C 10 -W 3 -w /home/myTrace.cap
 
You will see the following traces being created:
myTrace.cap0
myTrace.cap1
myTrace.cap2
 
After myTrace.cap2 is full, the tcpdump command will overwrite myTrace.cap0
 
For roughly 955 MB files, rotating through 8 files, use the following:
tcpdump -i eth0 -s 0 -C 1000 -W 8 -w /some/other/location/serverTrace.cap
 
You will see the following traces created:
serverTrace.cap0
serverTrace.cap1
.... and so on
serverTrace.cap8
 
When dealing with larger traces, and trying to capture a specific issue, it is usually not necessary to send in all of the traces to Novell support.  Typically the issue will be in the last one or two traces (depending on the settings used and the amount of traffic on the wire at the time).
 
-------------------------
 
Ethereal or Wireshark can also be used on Linux to take a packet trace.  See the following TID for more detail:
3892415 - How to use Wireshark to capture a packet trace