Every other network tool tells you what a program thinks happened: the connection timed out, the lookup failed, the server did not respond. tcpdump tells you what went onto the wire and what came back, which is a different thing more often than you would hope. It is the tool for the argument between two teams about whose side dropped the packet, and it settles that argument in about thirty seconds once you know six flags and ten filters.
sudo tcpdump -nn -i eth0 'tcp port 443 and host 203.0.113.7'-nn stops it resolving hostnames and service names, which is slow, noisy, and sends DNS queries of its own into the capture; -i names the interface, and -i any takes all of them; the quoted expression is the filter, compiled into a tiny program the kernel runs on every packet so that only the ones you asked for are copied up. Without a filter on a busy server you will be reading your own SSH session scrolling past.
17:36:19.924453 IP 127.0.0.1.55888 > 127.0.0.1.8090: Flags [S], seq 2952116781, win 65495, options [mss 65495,sackOK,TS val 3612251972 ecr 0,nop,wscale 10], length 0
17:36:19.924468 IP 127.0.0.1.8090 > 127.0.0.1.55888: Flags [S.], seq 3218126346, ack 2952116782, win 65483, options [mss 65495,sackOK,TS val 1563953311 ecr 3612251972,nop,wscale 10], length 0
17:36:19.924481 IP 127.0.0.1.55888 > 127.0.0.1.8090: Flags [.], ack 1, win 64, options [nop,nop,TS val 3612251972 ecr 1563953311], length 0
17:36:19.924557 IP 127.0.0.1.55888 > 127.0.0.1.8090: Flags [P.], seq 1:78, ack 1, win 64, options [nop,nop,TS val 3612251972 ecr 1563953311], length 77
17:36:19.928027 IP 127.0.0.1.8090 > 127.0.0.1.55888: Flags [F.], seq 477, ack 78, win 64, options [nop,nop,TS val 1563953314 ecr 3612251975], length 0That is a complete TCP connection in five lines: a timestamp, source and destination with the port after the last dot, and the flags. Learn the flags and you can read any capture.
| Flags | Meaning | If you see it alone, repeatedly |
|---|---|---|
[S] | SYN: a new connection being opened | SYNs with no [S.] coming back: nothing answering, or the reply is being dropped |
[S.] | SYN-ACK: the server accepted the handshake | — |
[.] | ACK only: acknowledging data, no payload | — |
[P.] | PSH-ACK: data, delivered to the application without waiting | — |
[F.] | FIN: this side has finished sending | One side’s FIN never answered: the other application has not closed |
[R] / [R.] | RST: refused, or torn down abruptly | An [R.] straight after your [S] is “connection refused”: the host is up and nothing is listening |
Where tcpdump stands, and what that means
tcpdump sees incoming packets before the firewall and outgoing packets after it. On Linux the capture point is the network device: inbound, a packet is copied to tcpdump as it arrives, before any netfilter rule has run; outbound, it is copied as it leaves, after the rules have had their say. So a capture is not proof that the firewall let a packet through, and the absence of a reply in the capture is the thing to read. If an inbound [S] appears and nothing goes back, the host dropped it — a DROP rule or a listener that is not there with a REJECT rule converting the refusal into silence. If an [R.] goes back, the packet got past the firewall to a port with nothing listening. If an [S.] goes back and the client never sees it, the loss is on the return path and not on this machine at all. The same rule in reverse explains a client that “sends” and nothing appears: an OUTPUT rule dropped it before the capture point, so it never existed as far as tcpdump is concerned. Run the capture on both ends and the gap between them is where the packet died.
# refused, measured: a SYN to a closed port and the RST that answers it
17:38:35.289307 IP 127.0.0.1.48428 > 127.0.0.1.8091: Flags [S], seq 4269196277, win 65495, options [...], length 0
17:38:35.289318 IP 127.0.0.1.8091 > 127.0.0.1.48428: Flags [R.], seq 0, ack 4269196278, win 0, length 0The ten filters
The filter language is small, and these cover nearly everything a server administrator needs. Combine them with and, or, not and parentheses, and quote the whole expression so the shell leaves it alone.
| Filter | Matches |
|---|---|
host 203.0.113.7 | Either direction to or from that address; src host / dst host for one direction |
net 10.0.0.0/8 | Anything in that network |
port 443 | Either end on that port; src port / dst port to pick an end. portrange 8000-8100 for a span |
tcp / udp / icmp / arp | One protocol. icmp is how you see the “unreachable” messages that explain a silent failure |
not port 22 | Everything except your own SSH session; add it to nearly every interactive capture |
'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn' | Only connection attempts: one line per new connection, nothing else |
'tcp[tcpflags] & tcp-rst != 0' | Only resets: refusals and abrupt closes |
'tcp[tcpflags] & tcp-push != 0' | Only segments carrying data, for reading a protocol with -A |
vlan and host 203.0.113.7 | On a trunk port; without vlan first, tagged frames do not match host at all |
less 100 / greater 1400 | By frame size: tiny keepalives, or full-size segments that may be fragmenting |
Writing a capture file, and reading it back
Reading live output is for the quick question. For anything you will need to look at twice, or show someone, write the raw packets to a file and analyse afterwards — in tcpdump itself, or in Wireshark on your laptop, which reads the same format:
sudo tcpdump -nn -i eth0 -w /tmp/web.pcap 'tcp port 443 and host 203.0.113.7'
# ... reproduce the problem, then Ctrl-C ...
tcpdump -nn -r /tmp/web.pcap -tttt # read it back, with full dates
tcpdump -nn -r /tmp/web.pcap 'tcp[tcpflags] & tcp-rst != 0' # filters work on files too
tcpdump -nn -r /tmp/web.pcap -A 'tcp dst port 80 and tcp[tcpflags] & tcp-push != 0'Write to /tmp or /var/tmp rather than your home directory: on Debian and Ubuntu, tcpdump drops from root to its own unprivileged user before opening the output file, and a directory that user cannot write to produces a Permission denied that looks like a bug. -Z root turns the privilege drop off when you must write elsewhere.
For a problem that happens “sometimes”, leave a rotating capture running and come back when it has. The two rotation modes behave differently in a way that matters:
# by size: a ring of three 100 MB files, oldest overwritten, runs until stopped
sudo tcpdump -nn -i eth0 -w /var/tmp/ring.pcap -C 100 -W 3 'port 5432'
# by time: a new file every hour -- and after three files tcpdump EXITS
sudo tcpdump -nn -i eth0 -w '/var/tmp/pg-%Y%m%d-%H%M.pcap' -G 3600 -W 3 'port 5432'That second behaviour was measured for this page: with -G and -W, the third file completes and tcpdump stops with Maximum file limit reached: 3. It is documented, and it is still a surprise the first time a capture you meant to run all weekend turns out to have ended on Friday evening. For “keep the last N hours” use -G without -W and a cron job to delete old files, or use the size-based ring.
Looking inside the packets
$ tcpdump -nn -r http.pcap -A 'tcp dst port 8090 and tcp[tcpflags] & tcp-push != 0'
17:38:34.331384 IP 127.0.0.1.45046 > 127.0.0.1.8090: Flags [P.], seq 3136825360:3136825437, ack 4014313449, win 64, options [...], length 77
E.....@.@.g...............(..E.....@.u.....
......R.GET / HTTP/1.1
Host: 127.0.0.1:8090
User-Agent: curl/8.5.0
Accept: */*-A prints the payload as text and is enough for HTTP, SMTP, Redis, PostgreSQL’s startup message and anything else that talks in ASCII; -X prints hex and text side by side for binary protocols. Neither helps with TLS, where the payload is ciphertext by design — for an HTTPS problem, tcpdump shows you the handshake (the ClientHello and whether a ServerHello came back, with -v) and the timing, and the rest belongs to openssl s_client. -v and -vv add the IP header (TTL, fragmentation flags), checksums, and fuller decoding of DNS, ICMP and TLS records.
The flags that matter
| Flag | Does |
|---|---|
-nn | No name resolution for hosts or ports. Always |
-i IFACE | Interface; -i any for all, with an In/Out direction column. -D lists them |
-w FILE / -r FILE | Write raw packets to a file / read them back. - is stdout, for piping to another host’s Wireshark |
-c N | Stop after N packets |
-A / -X | Payload as ASCII / as hex and ASCII |
-v, -vv | More header detail and protocol decoding |
-tttt / -ttt | Full date and time on each line / time since the previous packet |
-q | Quiet: shorter lines, protocol and length only |
-e | Link-layer header: MAC addresses and VLAN tags |
-s N | Snapshot length, bytes captured per packet. The default is 262144 — the whole packet; -s 0 is an old habit that now means the same thing |
-C MB -W N / -G SEC -W N | Rotate the output file by size (ring) / by time (then exit, see above) |
-U / --print | Flush each packet to the file as it arrives / print to the terminal as well as writing the file |
-B KB | Kernel capture buffer size; raise it when the final line reports packets dropped by kernel |
-Z USER | User to drop privileges to; -Z root to keep them |
The last three lines
25 packets captured
96 packets received by filter
0 packets dropped by kernelRead them every time. Captured is what tcpdump processed; received by filter is what the kernel’s filter looked at, which on Linux includes packets that arrived before the filter was fully installed and packets still in the buffer when you stopped, so the two rarely agree and that is not a problem. Dropped by kernel is the one that matters: any number other than zero means the buffer overflowed and the capture has holes in it, and a missing packet in an incomplete capture is not evidence of anything. Tighten the filter, write to a file instead of the terminal, and raise -B.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| Output is a wall of your own SSH traffic | No filter, or a filter that does not exclude port 22 | '... and not port 22' |
| Lines appear seconds late, hostnames everywhere, extra DNS in the capture | Name resolution on | -nn |
cksum 0x... (incorrect -> 0x...) on every outgoing packet with -v | Checksum offload: the NIC fills it in after the capture point | Not an error. Ignore on transmit; on receive it would be real |
Permission denied opening the -w file as root | Privilege drop to the tcpdump user before the file is opened | Write under /tmp or /var/tmp, or -Z root |
| A time-rotated capture stopped on its own | -G with -W N exits after N files | Drop -W and prune old files, or rotate by size with -C |
packets dropped by kernel is not zero | Buffer overflow: too much traffic for the filter and the output | Narrower filter, -w to a file, -B 65536 or more |
| Nothing matches on a trunk interface | 802.1Q tags shift the headers; host and port look in the wrong place | Prefix the filter with vlan and |
Traffic between two containers is invisible on eth0 | It never leaves the host; it crosses a bridge or veth pair | -i docker0, -i br-…, the veth, or -i any |
You see the request leave but tcpdump on the server shows nothing | Dropped between the two: a middle firewall, a wrong route, or the far side’s inbound rule did not get that far | Capture on both ends; the hop that saw it last is where to look next |
-A shows garbage for HTTPS | TLS; the payload is encrypted | Read the handshake with -v; use openssl s_client for the rest |
Quick reference
sudo tcpdump -nn -i eth0 'host 203.0.113.7 and not port 22' # one peer, minus your session
sudo tcpdump -nn -i any 'port 53' # DNS, every interface
sudo tcpdump -nn -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn' # new connections only
sudo tcpdump -nn -i eth0 'tcp[tcpflags] & tcp-rst != 0' # refusals and resets
sudo tcpdump -nn -i eth0 icmp # unreachables, the silent-failure explainer
sudo tcpdump -nn -i eth0 -A 'tcp port 80 and tcp[tcpflags] & tcp-push != 0' # read the HTTP
sudo tcpdump -nn -i eth0 -w /tmp/x.pcap -c 1000 'port 5432' # a thousand packets to a file
tcpdump -nn -r /tmp/x.pcap -tttt 'host 10.0.0.5' # read it back, filtered, dated
sudo tcpdump -nn -i eth0 -w /var/tmp/ring.pcap -C 100 -W 5 'port 443' # 500 MB ring, runs until stopped
sudo tcpdump -nn -i eth0 -w - 'port 443' | ssh laptop 'wireshark -k -i -' # live into Wireshark elsewhereRelated reading
- The Life of a Packet — where the capture point sits relative to routing, netfilter and the queue, in both directions
- The Life of a TCP Connection — the handshake, the retransmit ladder and the close as a sequence of flags
- ss — the socket table’s view of the same connections;
tcpdumpfor the wire,ssfor the kernel’s state - Linux Firewalls — the DROP and REJECT rules that decide what the capture does and does not show
- DNS Resolution — reading a
port 53capture: the query, the answer, and the retry that means the first one was lost - Networking Basics — the diagnosis that leads here when
curlandsshave run out

