tcpdump prints packet headers and payloads matching an expression. It works at the raw socket level and sees everything that crosses the network interface.
tcpdump -i eth0Capture on interface eth0. Without -i, tcpdump picks the first available interface.
tcpdump -nnThe -n flag skips DNS lookups for IPs, and a second n skips port-to-service resolution. Always use -nn — it’s faster and produces cleaner output.
tcpdump -w capture.pcap
tcpdump -r capture.pcapWrite raw packets to a file with -w, read them back with -r. PCAP files can be opened in Wireshark for deeper analysis.
tcpdump -c 100Exit after capturing 100 packets. Essential when troubleshooting — you rarely need millions of packets.
tcpdump uses Berkeley Packet Filter (BPF) syntax — powerful, compact, and essential to master.
# Traffic to or from a specific host
tcpdump host 10.0.0.5
# Traffic from a source
tcpdump src 10.0.0.5
# Traffic to a destination
tcpdump dst 10.0.0.5tcpdump port 80
tcpdump portrange 8000-9000
tcpdump src port 443tcpdump icmp
tcpdump arp
tcpdump tcp
tcpdump udp
tcpdump ip
tcpdump ip6# TCP on port 443 that is not from 10.0.0.1
tcpdump tcp port 443 and not host 10.0.0.1
# DNS queries only
tcpdump port 53 and udp
# SSH traffic or HTTP traffic
tcpdump port 22 or port 80tcpdump -A port 80Prints each packet’s payload as ASCII. Useful for inspecting HTTP request bodies or response content.
tcpdump -X port 443Shows packets in both hex and ASCII. Essential for analyzing binary protocols.
tcpdump -eShows MAC addresses. Useful when diagnosing ARP issues or switch-level problems.
tcpdump -vv port 53More vs give more detail — TTL, IP options, TCP options, checksums.
tcpdump -s 0-s 0 captures the entire packet. Default is 262144 bytes. For performance, limit with -s 1500 (MTU-sized) to skip large packet payloads.
tcpdump -nn -c 10 port 53Trigger a DNS lookup and watch the query and response. If you see queries but no responses, DNS is blocked. If you see “NXDOMAIN”, the record doesn’t exist.
tcpdump -nn -i any tcp port 80Watch the TCP handshake. A delayed SYN-ACK suggests the server is overloaded or the network path has issues. Use -w and analyze timing in Wireshark.
A client reports “no response” from the server. Capture server-side:
tcpdump -nn -i eth0 tcp port 8080 -c 100 -w /tmp/server.pcapIf you see the server sending SYN-ACK and data, the problem is the network path or the client. If the server never sees the SYN, the traffic isn’t reaching it.
tcpdump -nn -c 10000 -w /tmp/dump.pcapThen analyze:
tcpdump -r /tmp/dump.pcap -nn | awk '{print $3}' | cut -d. -f1-4 | sort | uniq -c | sort -rn | head -10This shows the top source IPs by packet count.
13:45:12.123456 IP 10.0.0.1.54322 > 10.0.0.2.80: Flags [S], seq 12345, win 65535
13:45:12.123456IP10.0.0.1 port 54322> (outgoing)10.0.0.2 port 80[S] (SYN)Common TCP flags:
[S] — SYN (connection start)[.] — ACK (acknowledgment)[P] — PUSH (data being sent)[F] — FIN (connection close)[R] — RST (connection reset — usually indicates an error)On high-throughput interfaces, tcpdump itself can drop packets:
tcpdump -nn -i eth0 -c 100000 2>&1 | grep droppedIf you see packet drops, use a larger buffer:
tcpdump -B 4096 -nn -i eth0Or capture only what you need with precise BPF filters. Never run tcpdump -i any on a 10Gbps interface without a filter — you will drop most packets and potentially saturate CPU.
Related Articles
tcpdump — Network Packet Analysis for Sysadmins
Use tcpdump to capture and analyze network traffic like a senior network engineer. Debug DNS, TCP handshakes, and slow connections.
DNS Demystified 4: Troubleshooting DNS Issues
A systematic approach to diagnosing DNS problems — from NXDOMAIN to SERVFAIL, slow resolution, and misconfigured zones.
lsof and ss — Open Files and Sockets Deep Dive
Master lsof and ss to find what files are open, which processes hold sockets, and why you cannot unmount a filesystem.