tcpdump for Busy Admins: The Twenty Filters Worth Memorizing
tcpdump is the command-line packet capture tool. It is already installed, or one package away, on nearly every Linux and Unix-like system you will ever touch. That includes many firewalls and appliances. Point it at a network interface and it prints each packet as a one-line summary, live, as it happens. No GUI, no setup, no waiting: when something is wrong right now, tcpdump is the fastest way to watch the wire.
Its power is gated behind filter expressions — a small language (called BPF, for Berkeley Packet Filter) that tells tcpdump which packets you want. You could study that language like a grammar. Do not. Learn it like a phrasebook instead. Twenty phrases cover the situations that actually recur in admin life, and this guide is that phrasebook. Each entry gives you the one-liner, what it catches, when you reach for it, and what the output looks like. Then come the handful of flags that keep you safe and a crash course in reading tcpdump's output. Finally, there is the filter-writing discipline that prevents silently wrong answers.
In this guide
- Filters 1–5: hosts, directions, and subnets
- Filters 6–10: ports and protocols
- Filters 11–12: cutting the noise
- Filters 13–16: hunting TCP state
- Filters 17–20: elephants and the VLAN trap
- The six flags that keep you safe
- Reading the one-line output
- Filter discipline: narrow, verify, parenthesize
- The printable twenty
- Where to go next
Before the first command: capturing requires root or administrator rights, and it records real traffic. Run it only on systems and networks you are authorized to inspect, and treat saved captures as sensitive data (see capture hygiene). All examples below use -ni eth0; swap in your interface name.
Filters 1–5: hosts, directions, and subnets
The first five phrases isolate who. Almost every capture starts with one of them.
1. Everything for one machine
tcpdump -ni eth0 host 10.0.8.5
Every packet to or from that address. This is the opening move of most investigations — "what is this box actually doing?" — and the output is a scrolling honest diary. It shows DNS lookups, handshakes, data, everything. Each line pairs 10.0.8.5 with one conversation partner.
2 and 3. One direction only
tcpdump -ni eth0 src host 10.0.8.5 tcpdump -ni eth0 dst host 10.0.8.5
src shows only what the machine sends; dst only what arrives. Reach for these when the question has a direction. "is this server spraying traffic outward?" is a src question. "what keeps hammering it?" is a dst question. Same output format as filter 1, but every line points the same way.
4. One conversation
tcpdump -ni eth0 host 10.0.20.31 and host 10.0.8.5
Only packets traveling between those two machines, in either direction. This is the filter for the classic disagreement — client says sent, server says never arrived. That is because it isolates exactly one relationship from everything else on the wire. If the decision to capture came from a specific conversation, this phrase is your default.
5. A whole subnet
tcpdump -ni eth0 net 10.0.30.0/24
Any packet with either end in that address range. This is useful for segment-level questions. What is the guest VLAN doing? Is anything from the printer subnet touching the server range? For that, combine: net 10.0.30.0/24 and net 10.0.8.0/24. Expect bursty, mixed output — this one pairs well with the noise cutters below.
Filters 6–10: ports and protocols
The next five isolate what service. Ports name applications; protocols name families.
6. DNS, the usual suspect
tcpdump -ni eth0 port 53 12:02:11.408 IP 10.0.20.31.55123 > 10.0.8.10.53: 41718+ A? files.corp.example. (36) 12:02:11.409 IP 10.0.8.10.53 > 10.0.20.31.55123: 41718* 1/0/0 A 10.0.8.44 (52)
port 53 matches either endpoint's port, UDP or TCP. Since a remarkable share of "the network is broken" is really "DNS is broken," this earns its place early. tcpdump decodes DNS beautifully. The query line shows what was asked (A? files.corp.example.). The reply shows the answer — or conspicuously never appears, which is your diagnosis.
7. Protocol plus port
tcpdump -ni eth0 tcp port 443 tcpdump -ni eth0 udp port 514
Prefixing tcp or udp narrows a port to one transport. This is useful when a port number is shared or you only care about one side of the TCP/UDP split. Habit-forming and free; be as specific as you know how to be.
8. A block of ports
tcpdump -ni eth0 tcp portrange 8000-8099
For applications that spread across a range — media systems, backup agents, development servers. Saves writing ten or clauses, and works for src portrange and dst portrange too.
9. ICMP: the network's apology notes
tcpdump -ni eth0 icmp 12:05:40.221 IP 10.0.0.1 > 10.0.20.31: ICMP host 203.0.113.9 unreachable, length 36
This catches ping traffic, yes — but the real prize is the error messages: destination unreachable, fragmentation needed, time exceeded. These are the network formally apologizing for a delivery failure, and they name names. When transfers stall mysteriously or connections die without a reset, run this filter and see who is apologizing for what.
10. ARP: the local neighborhood
tcpdump -ni eth0 arp 12:06:02.112 ARP, Request who-has 10.0.20.1 tell 10.0.20.31, length 28 12:06:02.113 ARP, Reply 10.0.20.1 is-at 84:2b:2b:11:22:33, length 46
ARP is how machines on the same segment find each other's hardware addresses, and its who-has/is-at dialogue is wonderfully readable. Reach for it when hunting a duplicate IP address. Two different is-at answers for one address — there is your culprit. Also reach for it when "nobody can reach the gateway," or when you want to see a mystery device announce itself.
Filters 11–12: cutting the noise
Two subtraction phrases. The first one, everybody learns the hard way exactly once.
11. Not my own session
tcpdump -ni eth0 not port 22
Here is the rite of passage. You SSH into a server, run tcpdump with no filter, and the screen erupts. That is because every line tcpdump prints travels back to you over SSH, generating packets, which tcpdump prints, generating packets. You have built a feedback loop starring yourself. not port 22 breaks the loop. When you need to watch other SSH traffic while excluding only your own, refine it: 'not (host 10.0.20.31 and port 22)' with your workstation's address.
12. Not the background hum
tcpdump -ni eth0 not broadcast and not multicast
Quiet segments are never actually quiet: ARP shouts, discovery protocols, routing hellos, and assorted service announcements hum along constantly. This phrase mutes the hum so a lone interesting unicast conversation stands out. (Skip it when the broadcast traffic is the investigation — ARP storms, discovery floods.)
Filters 13–16: hunting TCP state
TCP packets carry flag bits — SYN to open, ACK to acknowledge, FIN to close politely, RST to slam the door. Filtering on them turns tcpdump into a connection-drama detector. The syntax peeks at the flags byte: tcp[tcpflags], with named constants. These expressions contain characters your shell wants to interpret, so wrap them in single quotes, always.
13. Connection attempts only
tcpdump -ni eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn'
Matches packets with SYN set and ACK clear: the opening packet of every connection attempt, with all established chatter invisible. There are three great uses. You can see who still connects to a server you hope to decommission. You can spot a port scan: one source politely knocking on dozens of ports, Flags [S] over and over. And you can confirm an application is even trying to connect.
14. Connections accepted
tcpdump -ni eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)'
The mirror image: SYN and ACK both set — the second step of the handshake, sent by a service saying yes. Attempts (filter 13) without matching accepts (filter 14) mean a service that is down, full, or firewalled. Run the two filters in two terminals and you have a live accept-versus-refuse monitor built from nothing.
15. Reset hunting
tcpdump -ni eth0 'tcp[tcpflags] & tcp-rst != 0'
RST is TCP's door slam. It might mean nothing listening on that port, or a firewall rejecting instead of dropping. It might mean a middlebox killing sessions it considers idle, or an application aborting. When users report "connection reset by peer," this filter shows you who sent the reset — which is the entire mystery. Watch the source address on the Flags [R] lines. Resets from a device in the middle, rather than either endpoint, are the smoking gun of an interfering box.
16. Retransmissions — the honest version
tcpdump -nSi eth0 host 10.0.8.5 and port 445
Honesty first: tcpdump filters are stateless. Each packet is matched alone, so no filter can catch "retransmission," which is by definition a relationship between packets. What you can do is make repeats visible to the eye. -S prints absolute sequence numbers. So the same seq range appearing twice is a retransmission, easy to spot in a modest conversation. For real retransmission bookkeeping, capture to a file and let Wireshark's analysis engine flag them all.
Filters 17–20: elephants and the VLAN trap
Two phrases for finding heavy flows by packet size, and two for the trunk-port gotcha that silently breaks all the others.
17. The elephant detector
tcpdump -ni eth0 greater 1200
Matches only packets of 1200 bytes or more. Bulk data rides in full-size packets; chatter, acknowledgments, and queries are small — so this filter is a crude but instant bulk-transfer detector. Silence means nothing big is moving through your vantage point. A steady roar means a transfer is underway, and the addresses on those lines name it.
18. The elephant, aimed
tcpdump -ni eth0 dst host 10.0.8.5 and greater 1200
Who is pushing bulk data into this machine right now (swap dst for src for outbound). A sixty-second coarse answer when the link is hot and you are standing at a console. For sustained who-uses-the-bandwidth questions, though, this is the wrong rung of the ladder — flow data answers those without a capture at all.
19. Is this traffic tagged?
tcpdump -ni eth0 vlan
Matches frames carrying an 802.1Q VLAN tag — the four extra bytes trunk links insert to label each frame's VLAN. Run this first whenever you capture on a trunk or on a mirror of one. If it shows traffic, your frames are tagged. In that case, the tag changes everything about how the other nineteen filters behave. Which brings us to the trap.
20. VLAN first, then everything else
tcpdump -ni eth0 'vlan and host 10.0.30.5'
Here is the gotcha. The tag shifts every field in the frame four bytes to the right. The vlan keyword is what tells tcpdump to account for the shift — but only for the parts of the expression after it. So 'vlan and host 10.0.30.5' finds your host inside tagged frames, while 'host 10.0.30.5 and vlan' looks for the address at the untagged offsets and silently matches nothing. Same words, opposite results. On trunks: vlan goes first, every time. (You can also target one VLAN: 'vlan 30 and host 10.0.30.5'.)
The six flags that keep you safe
The filter chooses packets; the flags control the tool. Six of them do nearly all the work:
| Flag | What it does | Why it matters |
|---|---|---|
-i eth0 | Choose the interface | tcpdump -D lists interfaces; -i any sees them all at once, at some cost in link-level detail |
-n | No name lookups | Always. Reverse-DNS lookups stall the display and generate traffic into your own capture |
-c 100 | Stop after N packets | Self-limiting commands can't be forgotten and left running; perfect for test runs |
-w file.pcap | Write raw packets to a file | Capture now, analyze later — the bridge to Wireshark; read back with -r |
-s 128 | Snaplen: keep only the first N bytes of each packet | Headers-only capture for high-volume runs; the default keeps whole packets |
-v / -vv | More decode detail | Sparingly — useful for protocol detail like DNS and ICMP internals, noisy everywhere else |
Reading the one-line output
One annotated line teaches you to triage without leaving the terminal:
12:07:41.523419 IP 10.0.20.31.52114 > 10.0.8.5.445: Flags [P.], seq 3281:3405, ack 5121, win 501, length 124
Left to right: the timestamp, down to the microsecond — gaps between lines are your timing evidence. Then source address and port, an arrow, destination address and port: who is speaking to whom. Flags in brackets use one letter per flag. [S] is a connection attempt. [S.] is the acceptance (the dot means ACK). [.] is a plain acknowledgment. [P.] is data being delivered. [F.] is a polite close. [R] is the door slam. The seq range counts the data bytes this packet carries. ack is the next byte expected from the other side. win is how much the sender can currently receive. If it falls toward zero, someone's buffer is full and the conversation is about to stall. length is the payload size.
That is genuinely enough to triage. You can see who initiated, who reset, and whether data is flowing or only acknowledgments. You can see how big the payloads are, and where the long pauses fall. The deeper narrative reading — windows, retransmission patterns, the shape of a healthy close — is the subject of reading a TCP conversation like a story.
Filter discipline: narrow, verify, parenthesize
Three habits separate reliable captures from misleading ones.
Start narrow. Filter to the conversation your hypothesis names, then widen only if the answer is not there. Wide captures on busy links drown you and punish the machine doing the capturing.
Verify the filter matches something. A filter with a typo does not error — it just matches nothing, forever, while you conclude "no traffic" and build theories on it. So prove every filter against traffic you know exists. Add -c 10, generate the traffic yourself (a ping, a request), and watch the ten lines appear. Only a filter you have seen match deserves your trust when it goes quiet.
Parenthesize, and quote. Here is the classic silent failure. You want one server's web traffic, so you type:
# WRONG: means something else entirely tcpdump -ni eth0 host 10.0.8.5 and port 80 or port 443
and binds tighter than or, so this parses as (host 10.0.8.5 and port 80) or (port 443 from absolutely anyone). The output looks plausible — it is full of web traffic! — and you quietly conclude your server terminates far more HTTPS than it does. The fix is explicit grouping, and because parentheses are special characters to the shell, the whole expression goes in single quotes:
# RIGHT: this server's web traffic only tcpdump -ni eth0 'host 10.0.8.5 and (port 80 or port 443)'
Make the single quotes a reflex for any filter longer than two words. They also protect the &, |, and brackets in the TCP-flag filters, which shells otherwise eat with strange results.
The printable twenty
| # | Filter | Finds |
|---|---|---|
| 1 | host 10.0.8.5 | Everything for one machine |
| 2 | src host 10.0.8.5 | Only what it sends |
| 3 | dst host 10.0.8.5 | Only what reaches it |
| 4 | host A and host B | One conversation, both directions |
| 5 | net 10.0.30.0/24 | A whole subnet's traffic |
| 6 | port 53 | DNS queries and answers |
| 7 | tcp port 443 | One transport, one port |
| 8 | tcp portrange 8000-8099 | A block of app ports |
| 9 | icmp | Pings and error messages |
| 10 | arp | Who-has / is-at on the segment |
| 11 | not port 22 | Everything except your own SSH |
| 12 | not broadcast and not multicast | Unicast only; hum muted |
| 13 | 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn' | New connection attempts |
| 14 | 'tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)' | Connections accepted |
| 15 | 'tcp[tcpflags] & tcp-rst != 0' | Who is sending resets |
| 16 | -S plus host and port | Repeated seq = retransmission, by eye |
| 17 | greater 1200 | Bulk transfers in progress |
| 18 | dst host X and greater 1200 | Who pushes bulk into X |
| 19 | vlan | Any 802.1Q-tagged frames |
| 20 | 'vlan and host 10.0.30.5' | A host on a trunk — vlan first! |
Where to go next
Twenty phrases, six flags, one reading lesson, three habits — that is a working command of tcpdump, and it will serve you for a career. The natural next step is the handoff. Capture with -w, then open the file in a graphical analyzer where streams, timings, and retransmissions become visible at a glance. Wireshark fundamentals picks up exactly there. For problems that refuse to occur while you watch, ring buffers and long-running captures extends these same one-liners into standing traps. The whole discipline, start to finish, lives at Packet Capture & Analysis.
Put this into practice with SysPeep Monitor
tcpdump is the tool you grab once something is already wrong. SysPeep Monitor is the one watching beforehand. It auto-discovers your devices and tracks port status, traffic, errors, and health over SNMP, WMI, and SSH. Its alerts name the host and port worth investigating. So your first filter is aimed at the right place. The free trial installs on a Windows machine in minutes.
Download Free TrialLearn About SysPeep