Packet capture with tcpdump
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 eth0selects the interface (-i anylistens on all).-nand-nnskip name and port-name lookups, which are slow and add traffic.-c 100stops after 100 packets.-w filesaves them for later analysis.- Filters such as
host,port,tcp,udpandand/orkeep 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 64240Source 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.