tcpdump: practical filters for everyday troubleshooting
Capture the right traffic with tcpdump: common filters, TCP flags, DNS checks, Wireshark handoff, and WireGuard capture points.
This guide is a working reference for tcpdump. Start with a small capture to keep the evidence, then narrow your investigation as you learn more about what you’re searching for.
Replace interface names and addresses; the documentation addresses below are placeholders. Capture only traffic you are authorized to inspect, and handle PCAP files as potentially sensitive data.
Start with one endpoint
List the available capture interfaces, then select the interface that carries the traffic you want to investigate:
sudo tcpdump -D
sudo tcpdump -i eth0 -nn -c 30 'host 192.0.2.20'
The core options:
| Option | Purpose |
|---|---|
-i eth0 |
Select the interface. |
-n |
Disable name resolution for packet output, avoiding reverse-DNS lookups. |
-nn |
Keep addresses and ports numeric. |
-c 30 |
Stop after 30 matching packets; this is not a timer. |
-w case.pcap |
Write packet data to a capture file. |
-r case.pcap |
Read a saved capture. |
-tttt |
Include the date in printed timestamps. |
Stop a live capture with Ctrl+C. For interface details and version-specific behavior, consult your installed man tcpdump.
Use -n to avoid DNS lookups
-n disables name resolution when tcpdump displays packets. It is a command-line option, not a packet filter:
sudo tcpdump -i eth0 -n -c 30 'host 192.0.2.20'
Here, -n prevents reverse-DNS lookups for the displayed IP addresses. The host 192.0.2.20 expression selects the packets to capture.
You will also see -nn throughout this guide to keep addresses and ports numeric. Current upstream tcpdump already suppresses address and port-name conversion with -n; packaged versions can differ, so check your installed manual.
Without numeric output, tcpdump may perform reverse-DNS lookups to turn captured IP addresses into hostnames. Those queries add traffic and can appear in DNS resolver or authoritative-server logs. If the relevant DNS infrastructure is controlled or monitored by the party whose addresses you are investigating, the queries may reveal that those addresses are being examined. Avoiding these lookups reduces that extra disclosure, but does not guarantee undetectable analysis.
Use literal IP addresses in capture filters as well. A filter such as host example.com can still require a hostname lookup even with -n or -nn.
Common filters
Use an expression from the right column inside single quotes:
sudo tcpdump -i eth0 -nn -c 30 'EXPRESSION'
| Find | Expression |
|---|---|
| One host, either direction | host 192.0.2.20 |
| Packets from that host | src host 192.0.2.20 |
| Packets to that host | dst host 192.0.2.20 |
| Traffic involving a subnet | net 198.51.100.0/24 |
| Traffic between two hosts | host 192.0.2.20 and host 198.51.100.40 |
| TCP on port 443 | tcp port 443 |
| Conventional DNS over UDP or TCP | udp port 53 or tcp port 53 |
| ICMP for IPv4 or IPv6 | icmp or icmp6 |
| ARP | arp |
| A UDP port range | udp portrange 5000-5010 |
| Everything except TCP port 22 | not tcp port 22 |
| One IPv6 host | ip6 host 2001:db8::20 |
Group alternatives explicitly:
sudo tcpdump -i eth0 -nn \
'host 192.0.2.20 and (tcp port 443 or udp port 443)'
In this filter language, and and or have equal precedence and are evaluated left to right. Parentheses make the intended selection clear. src and dst describe packet endpoints, not whether an interface received or transmitted the packet.
A port number is a selection criterion, not proof of the application using it. In particular:
- DNS uses TCP as well as UDP. Port 53 does not include DNS-over-HTTPS or DNS-over-TLS.
- HTTP/3 runs over QUIC, which uses UDP. A TCP-only capture can miss that traffic.
icmpincludes error messages as well as echo requests and replies.
Read a TCP exchange
This is an illustrative line, not output collected from a lab:
09:41:12.123456 IP 192.0.2.20.53000 > 198.51.100.40.443: Flags [S], seq 1000, win 64240, length 0
Read it as a packet from 192.0.2.20:53000 to 198.51.100.40:443. [S] is SYN; [S.] is SYN+ACK; [.] is ACK; [R] is RST; [F.] is FIN+ACK. The printed TCP length is payload length, so zero does not mean an empty network frame.
A normal connection begins with SYN, SYN+ACK, and ACK. A reset means the connection is being reset; it does not, by itself, identify an attack or its cause.
For an IPv4 capture, these filters isolate useful flag combinations:
# SYN set and ACK clear
tcpdump -nn -r case.pcap \
'tcp[tcpflags] & (tcp-syn|tcp-ack) = tcp-syn'
# RST set
tcpdump -nn -r case.pcap 'tcp[tcpflags] & tcp-rst != 0'
These tcp[...] byte-access filters are IPv4-specific. For IPv6, retain a broader capture and inspect it with Wireshark or TShark.
tshark -r case.pcap -Y 'tcp.flags.syn == 1 && tcp.flags.ack == 0'
That command uses a Wireshark display filter, not tcpdump filter syntax.
Save once, investigate repeatedly
sudo tcpdump -i eth0 -nn -s 0 -c 500 \
-w case.pcap 'host 192.0.2.20'
tcpdump -nn -tttt -r case.pcap
tcpdump -nn -r case.pcap 'tcp port 443'
-s 0 selects tcpdump’s default snapshot length: 262144 bytes in the current upstream manual, a per-packet snapshot limit. Check the capture’s closing statistics: kernel drops indicate capture-side loss, not proof of loss along the application’s network path.
You can open case.pcap in Wireshark for deeper analysis. Its two filter types do different jobs:
| Filter | Example | Effect |
|---|---|---|
| Capture | tcp port 443 |
Limits what is captured. |
| Display | tcp.port == 443 |
Hides other captured packets from the current view. |
Removing a display filter reveals the hidden packets again. Packets excluded during capture were never saved. This is why it helps to capture enough context before narrowing your view.
Work through a failed connection
Suppose a client resolves a name but cannot reach the service. Plan the investigation before adding increasingly elaborate filters:
- Record the attempted destination. A successful lookup can return several IPv4 or IPv6 addresses. Check which address the application actually attempts.
- Observe the connection at the client. Look for the relevant flow in both directions. For TCP, inspect the handshake. For QUIC, remember the UDP path.
- Write down what the capture demonstrates. “SYNs leave this interface, but no replies appear here” is an observation. “The firewall dropped them” is a hypothesis.
- Move the observation point when needed. Compare a capture near the service with the client-side capture. Check routing, policy, and the listening service against the evidence.
- Keep the original capture and the reproduction steps. Record the time, interface, filter, client address, destination, and action that triggered the failure.
The discipline is to separate what you saw from what you think caused it. One capture rarely explains every part of the path.
WireGuard: outside and inside the tunnel
WireGuard is a useful example of why capture location matters. WireGuard transports encrypted packets over UDP and exposes a tunnel interface for the inner traffic.
# Outer transport: use your real physical interface and configured port
sudo tcpdump -i eth0 -nn -c 30 'udp port 51820'
# Inner traffic: use your real tunnel interface and peer address
sudo tcpdump -i wg0 -nn -c 30 'host 10.44.0.2'
Port 51820 is an example configuration, not a universal requirement. These two captures answer different questions: whether tunnel transport is visible, and whether the expected inner flow is visible. Removing WireGuard encapsulation does not remove encryption used by applications such as HTTPS.
For troubleshooting, try reproducing one connection while observing both capture points. If the expected flow is missing at one point, use that difference to choose the next check; do not treat it as a complete diagnosis.
Keep the first capture small
Begin with one reproducible problem and an endpoint filter. Save enough context to revisit your assumptions. Use the filter table to reduce noise, and move to Wireshark when you need a closer view of the conversation.
A useful next lab is to compare a successful connection, a refused connection, and an unanswered attempt. Write down the evidence that distinguishes them before deciding why each happened.