Cheat sheet
tcpdump cheat sheet
Packet capture on one page: tcpdump's options and filters, then tshark.
tcpdump
Prints the packets passing a network card, filtered by address, port or protocol: the ground truth.
tcpdump -ni eth0 host 10.0.2.10- Prints every packet to or from 10.0.2.10 on eth0.
tcpdump -ni eth0 icmp- Prints only ICMP: pings, and errors such as unreachable or time exceeded.
tcpdump -eni eth0 arp- Prints ARP requests and replies with the MAC addresses of each frame.
tcpdump -nni eth0 'tcp port 80'- Prints web traffic on port 80, with numeric ports.
tcpdump -ni any -c 20 'udp port 53'- Prints the first 20 DNS packets on any card.
tcpdump -nni eth0 'tcp[tcpflags] & tcp-syn != 0'- Prints SYN packets: connection attempts, and the SYN-ACKs that answer them.
tcpdump -D- Lists the cards tcpdump can capture on, any included.
tcpdump -nni eth0 -ttt 'tcp port 8080'- Starts each line with the time since the one before: the same SYN sent again after 1 s, then 2 s, is a connection nothing answers.
tcpdump -ni eth0 net 10.0.2.0/24- Prints packets to or from any address in 10.0.2.0/24.
tcpdump -ni eth0 'src 10.0.1.10 and dst port 443'- Prints only what 10.0.1.10 sends to HTTPS servers: and, or, not combine filters.
tcpdump -ni eth0 'host 10.0.2.10 and not port 22'- Prints a host's traffic but leaves out your own SSH session to it.
tcpdump -ni eth0 -w capture.pcap- Writes the packets to capture.pcap for Wireshark or a later read, printing nothing.
tcpdump -nr capture.pcap 'tcp port 80'- Reads a saved capture, with a filter like a live one.
tcpdump -ni eth0 -A 'tcp port 80'- Prints each packet's content as text: readable HTTP headers when the traffic is not encrypted.
tshark
Reads a capture file and dissects it: filter by protocol field, print chosen fields, follow a stream, export files.
tshark -r incident.pcap -q -z conv,tcp- Lists the TCP conversations in the file and how much each exchanged.
tshark -r incident.pcap -Y http.request -T fields -e ip.dst -e http.host -e http.request.uri- Prints every HTTP request's destination, host and URL, one per line.
tshark -r incident.pcap -q -z follow,tcp,ascii,1- Reassembles the second TCP connection into readable text, payloads and all.
tshark -r incident.pcap --export-objects http,/tmp/objs- Carves every file transferred over HTTP out of the capture into a directory.