Filters
BPF syntax: host, net, port, portrange, src/dst,
tcp/udp/icmp, combine with and/or/not:
Useful over an SSH session to exclude your own traffic:
and not port 22— otherwise you mostly see your own packets.
Captures packets to diagnose "is traffic even arriving"; without -n it resolves every IP through DNS and slows down.
sudo tcpdump -ni any port 80
port 80, no resolving
sudo tcpdump -ni any host IP
by host
sudo tcpdump -ni any 'tcp and not port 22'
TCP without your own ssh
sudo tcpdump -ni any -c 20
20 packets and stop
sudo tcpdump -ni any -A port 80
payload (HTTP text)
sudo tcpdump -ni any port 80 -w cap.pcap
to a file → Wireshark
tcpdump captures network packets — the last resort when it's unclear
whether traffic even arrives at all. Needs root.
-n skips resolving IPs, -nn also skips resolving ports; without them
tcpdump slows down on DNS lookups.
-n doesn't resolve IPs into names, -nn also doesn't resolve port
numbers into service names — without them tcpdump noticeably slows down
on DNS lookups for every new address. By default a packet is truncated to
part of its headers; -s 0 captures it in full, needed to see the
complete payload.
| Option | What it does | Example |
|---|---|---|
-i IFACE |
Interface to capture on; any captures on every interface at once. | sudo tcpdump -i any port 80 |
-n |
Do not resolve IP addresses to names. | sudo tcpdump -ni any |
-nn |
Resolve neither addresses nor port numbers to service names. | sudo tcpdump -nni any port 80 |
-c N |
Stop after capturing N packets. | sudo tcpdump -ni any -c 20 |
-w FILE |
Write a raw dump to a .pcap file instead of printing to the screen (for Wireshark). | sudo tcpdump -ni any port 80 -w cap.pcap |
-r FILE |
Read packets from a .pcap file instead of a live capture. | sudo tcpdump -r cap.pcap 'host 10.0.0.5' |
-A |
Show the packet payload as ASCII — useful for unencrypted HTTP. | sudo tcpdump -ni any -A port 80 |
-s N |
Capture length in bytes; 0 captures the whole packet. | sudo tcpdump -ni any -s 0 -w cap.pcap |
-X |
Show the packet payload in both hex and ASCII. | sudo tcpdump -ni any -X port 80 |
-e |
Show the link-layer header (MAC addresses). | sudo tcpdump -ni any -e |
Nothing found. Try a shorter query.
BPF syntax: host, net, port, portrange, src/dst,
tcp/udp/icmp, combine with and/or/not:
Useful over an SSH session to exclude your own traffic:
and not port 22— otherwise you mostly see your own packets.
On the server, sudo tcpdump -ni any port 80, then make a request from
the client. Packets show up — traffic arrives (the problem is in the
app/local firewall); silence — it doesn't arrive (route/firewall/wrong
network/wrong interface).
An asymmetric route or a firewall on the return path/client side. Capture on both sides at the same time.
Narrow it with a filter (host/port), limit with -c N, exclude your
own session (not port 22), write to .pcap and analyze in Wireshark.
tcpdump requires root (raw socket access). List interfaces with sudo
tcpdump -D or ip -br a.
Found an inaccuracy? Report an error in the article