Tcpdump Cheat Sheet
Tcpdump Cheat Sheet
Tcpdump Cheat Sheet
What is TCPDump?
tcpdump is a command-line tool used to capture traffic on the network and analyze captured
packets of data passing through your machine.
Its functionality is similar to Wireshark, but it’s especially helpful when you can’t access a
graphical user interface and when automation is essential. Therefore, you can run tcpdump
on remote servers or devices on demand or as a scheduled background job as part of an
\ executable script.
Several Linux distributions come pre-loaded with tcpdump; if not, use the distribution’s
package manager to install tcpdump. You can find the location of tcpdump on your operating
system with the command which tcpdump.
Capture commands
Use the following commands to capture data packets.
Filter Commands
\ You can add special filter expressions to the tcpdump keyword to pick out specific packets.
They’re especially helpful when you want to analyze saved packet capture files. Each filter
expression is a single- or multi-word parameter and its argument, separated by spaces. You
may also apply logical operators to combine two filter expressions.
Display Commands
These tcpdump switches tell the terminal how to display the output.
With -A
-D tcpdump -D Print the list of the network interfaces
available on the system and on which
tcpdump can capture packets.
\
-e tcpdump -i eth0 -e Print the link-level header on each output
line, such as MAC layer addresses for
protocols such as Ethernet and IEEE
802.11.
-F tcpdump -i eth0 -F Use the file params.conf as input for
params.con /path/to/params.conf the filter expression. (Ignore other
f expressions on the command line.)
-n tcpdump -i eth0 -n Don't convert addresses (i.e., host
addresses, port numbers, etc.) to names.
-S tcpdump -i eth0 -S Print absolute, rather than relative, TCP
sequence numbers. (Absolute TCP
sequence numbers are longer.)
--time- tcpdump -i eth0 -- When capturing, set the timestamp
stamp- time-stamp- precision for the capture to tsp:
precision= precision=nano ● micro for microsecond (default)
tsp ● nano for nanosecond.
-t tcpdump -i eth0 -t Omit the timestamp on each output line.
-tt tcpdump -i eth0 -tt Print the timestamp, as seconds since
January 1, 1970, 00:00:00, UTC, and
fractions of a second since that time, on
each dump line.
-ttt tcpdump -i eth0 -ttt Print a delta (microsecond or nanosecond
resolution depending on the --time-
stamp-precision option) between the
current and previous line on each output
line. The default is microsecond
resolution.
-tttt tcpdump -i eth0 -tttt Print a timestamp as hours, minutes,
seconds, and fractions of a second since
midnight, preceded by the date, on each
dump line.
-ttttt tcpdump -i eth0 - Print a delta (microsecond or nanosecond
ttttt resolution depending on the --time-
stamp-precision option) between the
current and first line on each dump line.
The default is microsecond resolution.
-u tcpdump -i eth0 -u Print undecoded network file system
(NFS) handles.
-v tcpdump -i eth0 -v Produce verbose output.
Output Commands
Customize your tcpdump output with the following commands.
With -w option
Write each packet to the
output file out.pcap in real
time rather than only when
the output buffer fills.
Miscellaneous Commands
The following commands don’t fall into the categories above.
Here are logical operators that tcpdump uses, with 127.0.0.1 as a placeholder for
IPv4/IPv6 addresses:
Example Explanation
tcpdump -r outfile.pcap src host Print all packets in the file outfile.pcap
10.0.2.15 coming from the host with IP address
10.0.2.15
tcpdump -i any ip and not tcp Listen for non-HTTP packets (which have
port 80 TCP port number 80) on any network
interface
tcpdump -i eth0 -n >32 -w Save 30 packets of length exceeding 32
pv01.pcap -c 30 bytes to captures.pcap without DNS
resolution on the eth0 network interface
tcpdump -AtuvX icmp Capture ICMP traffic and print ICMP
packets in hex and ASCII and the following
features:
With:
● headers
● data
● undecoded NFS handles
Without:
● link level headers
● timestamps.
tcpdump 'tcp port 80 and Print all IPv4 HTTP packets to and from
(((ip[2:2] - ((ip[0]&0xf)<<2)) - port 80, i.e. print only packets that contain
((tcp[12]&0xf0)>>2)) != 0)' data, not, for example, SYN and FIN
\
packets and ACK-only packets.
Conclusion
We hope this tcpdump cheat sheet has been a handy guide in your studies and work.
Remember to check out our networking courses and articles on networking.
https://courses.stationx.net/p/the-complete-cyber-security-course-network-security
https://courses.stationx.net/p/linux-network-administration
https://courses.stationx.net/p/network-from-scratch-to-advanced-implementation