A quick-reference guide for packet capture, filtering, and network analysis using TCPDump—essential for netadmins and sysadmins troubleshooting connectivity, monitoring traffic, and diagnosing security issues.
This cheat sheet covers:
✔ Basic & advanced packet capture
✔ Filtering by host, port, protocol, and more
✔ Output customization & performance tuning
✔ Real-world use cases (HTTP, DNS, SSH, etc.)
TCPDump Cheat Sheet for NetAdmins & SysAdmins
Packet Capture, Filtering, and Analysis
1. Basic Capture
Capture on Any Interface
sh
tcpdump -i any
-i any: Listen on all interfaces.
Capture on Specific Interface
sh
tcpdump -i eth0
-i eth0: Listen on eth0.
Save Capture to File
sh
-w: Write raw packets to file (.pcap format).
Read from a PCAP File
sh
-r: Read from a saved capture file.
Limit Number of Packets
sh
-c 100: Capture only 100 packets.
2. Filtering Traffic
Filter by Host (IP)
sh
Capture traffic to/from192.168.1.100.
Filter by Source/Destination IP
sh
src: Only source IP.
dst: Only destination IP.
Filter by Port
sh
port: Single port.
portrange: Range of ports.
Filter by Protocol
sh
Capture only specific protocols.
Filter by Network (CIDR)
sh
Capture traffic within a subnet.
Combine Filters (AND/OR)
sh
Use and, or, not for complex filters.
3. Advanced Filtering (BPF Syntax)
Filter by TCP Flags
sh
tcp-syn: SYN packets.
tcp-ack: ACK packets.
tcp-rst: RST packets.
Filter by Packet Size
sh
greater: Packets larger than X bytes.
less: Packets smaller than X bytes.
Filter by MAC Address
sh
Capture traffic to/from a MAC address.
Filter VLAN Traffic
sh
Capture traffic on VLAN 100.
4. Output & Verbosity
Show IPs Instead of Hostnames
sh
-n: Disable DNS resolution (faster).
Verbose Output
sh
-v: More details (checksum, TTL, etc.).
Print Packet Contents (Hex & ASCII)
sh
-XX: Full packet hex dump.
Show Absolute Sequence Numbers
sh
-S: Displays raw TCP sequence numbers.
Timestamps
sh
-tttt: Human-readable timestamps.
5. Advanced Capture & Analysis
Capture Only HTTP Traffic
sh
-A: Print ASCII (useful for HTTP headers).
Capture FTP Passwords (Cleartext)
sh
FTP sends credentials in plaintext.
Capture DNS Queries
sh
Monitor DNS requests/responses.
Capture ICMP (Ping/Traceroute)
sh
Useful for troubleshooting connectivity.
Capture Only SYN Packets (New Connections)
sh
Filters TCP SYN packets (new connections).
6. Performance & Storage Optimization
Limit Packet Size
sh
-s 96: Capture only first 96 bytes (reduces size).
Rotate Capture Files
sh
-G 3600: Rotate file every hour.
Stop After X MB
sh
-C 100: Split files every 100MB.
Run in Background
sh
&: Run in background (use jobs to check).
7. Common Use Cases
Task
Command
Capture HTTP traffic
tcpdump -i eth0 port 80 -A
Capture SSH traffic
tcpdump -i eth0 port 22
Find suspicious IPs
tcpdump -n "src net 192.168.1.0/24"
Monitor VoIP (SIP/RTP)
tcpdump -i eth0 port 5060 or portrange 10000-20000
Detect ARP Spoofing
tcpdump -i eth0 arp
8. Quick Reference Table
Option
Description
-i eth0
Listen on eth0
-w file.pcap
Save to file
-r file.pcap
Read from file
-c 100
Capture 100 packets
-n
Disable DNS lookup
-v
Verbose output
-XX
Hex + ASCII dump
src/dst
Filter by source/dest
port 80
Filter by port
icmp/tcp/udp
Filter by protocol
Pro Tips:
✔ Use -n for faster captures (avoids DNS lookups).
✔ Combine with grep for deeper analysis:
sh
✔ Always verify permissions before capturing (sudo often required).