Drill: Capture and Filter Traffic with tcpdump¶
Goal¶
Use tcpdump to capture network traffic and apply filters by host, port, and protocol for targeted debugging.
Setup¶
- Linux system with tcpdump installed (
apt install tcpdumporyum install tcpdump) - Root access or CAP_NET_RAW capability
Commands¶
Capture all traffic on an interface:
Filter by host:
Filter by port:
Filter by protocol:
Combine filters with boolean logic:
tcpdump -i any 'host 10.0.0.5 and port 80'
tcpdump -i any 'src host 10.0.0.5 or dst host 10.0.0.6'
tcpdump -i any 'port 80 and not host 10.0.0.1'
Save capture to a file for later analysis:
Show packet contents in ASCII:
Show packet contents in hex and ASCII:
Disable name resolution for faster output:
What to Look For¶
- TCP flags: S (SYN), S. (SYN-ACK), . (ACK), F (FIN), R (RST)
- One-sided SYN without SYN-ACK suggests firewall blocking or host down
- RST packets indicate refused connections
- DNS queries and responses on port 53 reveal resolution behavior
Common Mistakes¶
- Forgetting
-nnand waiting for slow DNS reverse lookups on every packet - Not using
-cto limit capture count, filling disk with pcap data - Capturing on
eth0when traffic flows throughloor a bridge interface - Not quoting complex filter expressions, causing shell interpretation errors