Tcpdump Guide: Command-Line Packet Capture
Learn Tcpdump for command-line network packet capture and analysis with practical filters, output options, and security monitoring examples.
Why You Need Tcpdump
You need to see network traffic in real time from the command line — Tcpdump captures packets on any interface and displays or saves them for analysis. It uses BPF filter syntax for precise traffic selection and runs in environments where a GUI is unavailable.
Prerequisites
Installation
# Already installed on Kali
sudo apt install tcpdump # Other Debian-based systems
Basic Usage
sudo tcpdump -i eth0
sudo tcpdump -i eth0 -c 100
sudo tcpdump -i eth0 -w capture.pcap
tcpdump -r capture.pcap
Essential Options
| Option | Description |
|--------|-------------|
| -i INTERFACE | Network interface |
| -c COUNT | Stop after COUNT packets |
| -w FILE | Write to file |
| -r FILE | Read from file |
| -n | No hostname resolution |
| -nn | No hostname or port resolution |
| -v | Verbose output |
| -X | Hex and ASCII output |
| -A | ASCII output |
BPF Filter Expressions
# Host filters
sudo tcpdump -i eth0 host 192.168.1.100
sudo tcpdump -i eth0 src host 10.0.0.1
# Port filters
sudo tcpdump -i eth0 port 80
sudo tcpdump -i eth0 portrange 8000-8100
# Protocol filters
sudo tcpdump -i eth0 tcp
sudo tcpdump -i eth0 udp icmp arp
# Combined
sudo tcpdump -i eth0 tcp and port 80
sudo tcpdump -i eth0 not arp and not icmp
Reading Output
22:15:30.123456 IP 192.168.1.100.54321 > 93.184.216.34.80: Flags [S], seq 123456789, win 65535, length 0
Flags: [S] = SYN, [S.] = SYN-ACK, [.] = ACK, [P] = PUSH, [F] = FIN, [R] = RST.
Common Mistakes
Capturing on wrong interface. Not using -nn causes slow DNS resolution. Capturing without filters generates huge files.
Best Practices
Always use filters. Save captures first, analyze later. Use -nn for performance. Combine with Wireshark for deep analysis.
Related Tools
Related Articles
Summary
Tcpdump is the standard command-line packet capture tool. Key techniques include BPF filters, saving to files, and understanding output format.