appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Packet capture with tcpdump

Lesson 4 of 411 minIntermediate

See the real packets: capture, filter and read them.

When logs do not explain a network problem, look at the traffic itself. tcpdump captures packets on the command line, and Wireshark can open the same files with a graphical interface.

sudo tcpdump -i eth0 -n port 53              # DNS traffic, no name lookups
sudo tcpdump -i any -n host 10.0.0.5 and tcp port 443
sudo tcpdump -i eth0 -nn -c 100 -w capture.pcap   # save 100 packets to a file
  • -i eth0 selects the interface (-i any listens on all).
  • -n and -nn skip name and port-name lookups, which are slow and add traffic.
  • -c 100 stops after 100 packets. -w file saves them for later analysis.
  • Filters such as host, port, tcp, udp and and / or keep the output small.

Reading a line

10:21:04.123 IP 192.168.1.20.51234 > 93.184.216.34.443: Flags [S], seq 100, win 64240

Source address and port, destination address and port, and the TCP flags: [S] is a SYN, [S.] a SYN-ACK, [.] an ACK, [P.] data and [R] a reset. Seeing [S] repeated with no [S.] answer is a classic sign of a firewall dropping traffic.

CarefulA capture can contain passwords, cookies and private data (anything not protected by TLS). Capture only on systems you are authorised to analyse, and protect or delete the files afterwards.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. In tcpdump output, repeated [S] packets with no reply suggest:
2. Why use -n with tcpdump?
Hintsudo tcpdump -i eth0 -n port 53

Key terms