Updated 10 hours ago
When something breaks on a remote server at 2am and you're connected over SSH, you can't install Wireshark. But you have tcpdump. It's already there, waiting on nearly every Unix-like system, ready to show you exactly what's happening on the wire.
Every packet tells a story: who spoke, who answered, and what they said. tcpdump lets you read those stories.
Your First Capture
The simplest command captures everything on your default interface:
Packet summaries scroll past—timestamps, sources, destinations, protocols. On a busy network, this firehose of information overwhelms. You need filters.
To capture on a specific interface:
Not sure which interfaces exist? List them:
Saving Captures
Real-time analysis works for quick checks, but complex problems need saved captures:
The .pcap format is universal—open it later with tcpdump or transfer it to Wireshark for graphical analysis:
On busy networks, limit what you capture:
This stops after exactly 100 packets. For long-running captures, rotate files:
This creates 10 MB files, keeping only the 5 most recent (capture.pcap0 through capture.pcap4).
Filtering: Finding the Signal
The real power of tcpdump is filtering. Without filters, you're drowning in noise. With them, you see exactly the conversation you care about.
Capture traffic involving one host:
Capture traffic in one direction:
Filter by network:
Filter by port:
Filter by protocol:
Combining Filters
Logical operators create precise filters:
Seeing More
Packet summaries show metadata. To see actual content:
Disable name resolution for speed and clarity:
This prevents tcpdump from making DNS queries that might affect what you're diagnosing.
Reading the Output
A TCP packet looks like:
Breaking it down:
- 10:30:45.123456 — timestamp
- 192.168.1.100.54321 — source IP and port
- 203.0.113.50.80 — destination IP and port
- Flags [S] — TCP flags (S = SYN)
- seq 1234567890 — sequence number
- win 65535 — window size
- length 0 — payload bytes (0 for a SYN)
TCP flags tell the story:
- [S] — SYN: "I want to connect"
- [S.] — SYN-ACK: "Connection accepted"
- [.] — ACK: "Got it"
- [P] — PSH: "Here's data, process it now"
- [F] — FIN: "I'm done"
- [R] — RST: "Connection refused" or "Something's wrong"
Practical Troubleshooting
Can't reach a web server?
Try accessing the server while tcpdump runs. SYN packets going out but no SYN-ACK coming back? The server isn't responding. RST packets? Something is actively refusing the connection. The packets don't lie.
DNS problems?
Watch queries go out and responses come back. See which DNS server you're hitting and what it returns.
Capturing without capturing yourself?
Excludes your SSH session from the capture.
See all broadcast traffic:
Advanced Filters
Capture only TCP SYN packets (connection attempts):
Capture TCP RST packets (resets):
Capture HTTP GET requests:
This examines TCP payload for the bytes "GET " (0x47455420). The -s 0 captures full packets; -A displays as ASCII.
Piping to Wireshark
Capture on a remote server, analyze locally:
For real-time remote analysis:
The -U forces per-packet output; -w - writes to stdout. Wireshark's -k -i - starts immediately, reading from stdin.
Security Considerations
tcpdump captures everything—passwords, tokens, private data. Treat capture files as sensitive. Delete them when done.
It requires root because it puts interfaces into promiscuous mode, capturing all visible traffic including packets not addressed to your system.
On switched networks, you mainly see broadcast, multicast, and traffic destined for you. To capture traffic between other hosts, you need port mirroring or network taps.
Frequently Asked Questions About tcpdump
Was this page helpful?