tcpdump Tutorial: Capture and Read Network Traffic on Linux

Networking 8 min readUpdated Nov 18, 2026
4 views0 comments
A computer screen filled with colourful lines of program code
Photo: Markus Spiske / rawpixel (CC0, public domain). source

When logs and error messages stop helping, the network itself has the answer. tcpdump is a command-line packet analyser that shows exactly what enters and leaves a Linux machine: which hosts talk, which ports they use, whether a handshake completes, and whether a request ever gets a reply. It is installed or one command away on every major distribution, and it works over SSH. This tutorial teaches the options you need, how to read a capture line by line, how to filter the noise, and how to save traffic for Wireshark.

Use it responsibly. A packet capture can contain passwords, cookies and private messages. Capture only on systems and networks you own or are authorised to troubleshoot, keep capture files safe, and delete them when you are done.

Install and first run

sudo dnf install tcpdump       # RHEL, AlmaLinux, Rocky
sudo apt install tcpdump       # Debian, Ubuntu

tcpdump needs permission to read raw network traffic, so run it with sudo. List the interfaces it can listen on and pick one:

sudo tcpdump -D                # numbered list of interfaces
sudo tcpdump -i any -c 10      # first 10 packets on all interfaces, then stop

Without -c it captures until you press Ctrl+C, and on a busy server that floods the screen within seconds. Get into the habit of adding -c and a filter.

The options you will use every day

Option What it does
-i eth0 Capture on one interface (any means all of them)
-n Do not resolve IP addresses to names. Faster, and avoids DNS traffic polluting your capture
-nn Also show port numbers instead of service names (443, not https)
-c 20 Stop after 20 packets
-v, -vv More protocol detail (TTL, flags, checksums)
-A Print the packet payload as ASCII, handy for plain HTTP
-X Print the payload as hex and ASCII
-tttt Print a full date and time on each line
-w file.pcap Write raw packets to a file instead of the screen
-r file.pcap Read packets back from a file

A good default for almost every job is sudo tcpdump -nn -i INTERFACE followed by a filter.

A real capture, line by line

This capture was taken on the loopback interface while a single curl request was sent to a local web server on port 80. It shows a complete TCP connection from start to finish. (Long TCP option fields are shortened with ... so the lines fit.)

$ sudo tcpdump -i lo -nn -c 10 'tcp port 80'
listening on lo, link-type EN10MB (Ethernet), snapshot length 262144 bytes
00:08:35.251834 IP 127.0.0.1.32996 > 127.0.0.1.80: Flags [S], seq 3627073754, win 65495, ..., length 0
00:08:35.251870 IP 127.0.0.1.80 > 127.0.0.1.32996: Flags [S.], seq 2935432738, ack 3627073755, ..., length 0
00:08:35.251886 IP 127.0.0.1.32996 > 127.0.0.1.80: Flags [.], ack 1, win 512, ..., length 0
00:08:35.251938 IP 127.0.0.1.32996 > 127.0.0.1.80: Flags [P.], seq 1:74, ack 1, ..., length 73: HTTP: GET / HTTP/1.1
00:08:35.252007 IP 127.0.0.1.80 > 127.0.0.1.32996: Flags [.], ack 74, win 512, ..., length 0
00:08:35.252948 IP 127.0.0.1.80 > 127.0.0.1.32996: Flags [P.], seq 1:472, ack 74, ..., length 471: HTTP: HTTP/1.1 301 Moved Permanently
00:08:35.252961 IP 127.0.0.1.32996 > 127.0.0.1.80: Flags [.], ack 472, win 509, ..., length 0
00:08:35.253267 IP 127.0.0.1.32996 > 127.0.0.1.80: Flags [F.], seq 74, ack 472, ..., length 0
00:08:35.253448 IP 127.0.0.1.80 > 127.0.0.1.32996: Flags [F.], seq 472, ack 75, ..., length 0
00:08:35.253491 IP 127.0.0.1.32996 > 127.0.0.1.80: Flags [.], ack 473, win 512, ..., length 0
10 packets captured
20 packets received by filter
0 packets dropped by kernel

Every line follows the same pattern: time, protocol, source.port > destination.port, flags, sequence and acknowledgement numbers, window, length. Note that tcpdump writes the port as the last number of the address (127.0.0.1.80 is address 127.0.0.1, port 80). The story these ten lines tell:

  1. Lines 1 to 3, the handshake. The client (port 32996, a random source port) sends [S] (SYN). The server replies [S.] (SYN-ACK). The client answers [.] (ACK). The connection is open.
  2. Line 4, the request. [P.] means push plus acknowledgement: the client sends 73 bytes, and tcpdump recognises GET / HTTP/1.1.
  3. Lines 5 and 6, the answer. The server acknowledges the request and sends 471 bytes, an HTTP/1.1 301 Moved Permanently redirect.
  4. Lines 8 to 10, the close. Both sides send [F.] (FIN plus ACK) and acknowledge each other.

The flags you need to recognise

Flag Meaning What it tells you
[S] SYN A client is opening a connection
[S.] SYN-ACK The server accepted the connection
[.] ACK Acknowledgement, no data
[P.] PSH + ACK Data is being delivered
[F.] FIN + ACK A normal close
[R] or [R.] RST The connection was refused or aborted

The summary at the end is worth reading too. “packets dropped by kernel” above zero means tcpdump could not keep up, and your capture is incomplete. Add a tighter filter or write to a file.

Filtering: ask only for what you need

Filters use the BPF syntax and go at the end of the command. Quote them so the shell does not interpret the brackets or parentheses.

sudo tcpdump -nn host 203.0.113.10                # to or from one address
sudo tcpdump -nn src host 203.0.113.10            # only from it
sudo tcpdump -nn net 192.168.1.0/24               # a whole subnet
sudo tcpdump -nn port 443                         # one port, TCP or UDP
sudo tcpdump -nn portrange 8000-8100
sudo tcpdump -nn tcp                              # only TCP (also udp, icmp)
sudo tcpdump -nn 'tcp port 443 and host 203.0.113.10'
sudo tcpdump -nn 'udp port 53 or tcp port 53'
sudo tcpdump -nn 'not port 22'                    # everything except SSH
sudo tcpdump -nn 'tcp[tcpflags] & tcp-syn != 0'   # only packets with SYN set

Always exclude your own SSH session when you capture on a remote server with not port 22. Otherwise each line tcpdump prints travels over SSH, creates more packets, and prints those too, a feedback loop that fills the screen.

Combine conditions with and, or and not, and group them with quoted parentheses, for example 'host 203.0.113.10 and (port 80 or port 443)'.

Saving a capture and opening it in Wireshark

For anything longer than a few seconds, write the capture to a file and analyse it afterwards. Writing is also much faster than printing and loses fewer packets.

sudo tcpdump -nn -i eth0 -w /tmp/web.pcap 'tcp port 443 and host 203.0.113.10'
# reproduce the problem, then press Ctrl+C

sudo tcpdump -nn -r /tmp/web.pcap | head          # read it back in the terminal
scp user@server:/tmp/web.pcap .                   # copy it and open it in Wireshark

Wireshark gives you a graphical view with filters, the “Follow TCP stream” feature and statistics. A typical workflow is to capture on the server with tcpdump and examine on your desktop with Wireshark.

To capture over a long period without filling the disk, rotate the files: -C 100 -W 5 keeps five files of about 100 MB each and overwrites the oldest. Remember that the file may be owned by the tcpdump user, since tcpdump drops root privileges after opening the interface. Write into /tmp or a directory that user can write to.

Practical recipes

Question Command
Does the traffic reach this server at all? sudo tcpdump -nn -i any 'tcp port 8080', then connect from the client
Which DNS queries is this machine sending? sudo tcpdump -nn -i any 'udp port 53'
Is a ping arriving? sudo tcpdump -nn -i any icmp
Is DHCP answering? sudo tcpdump -nn -i any 'port 67 or port 68'
What does a plain HTTP request look like? sudo tcpdump -nn -A -i any 'tcp port 80'
Who is connecting to the web server? sudo tcpdump -nn -i any 'tcp port 443 and tcp[tcpflags] & tcp-syn != 0'

Reading the result: what the pattern means

What you see Meaning Next step
Repeated [S] from the client, no reply The SYN never gets an answer: a firewall drops it, or it never reached the server Check the firewall (firewall-cmd --list-all), cloud security groups and routing
[S] followed by [R.] The server answered with a reset: the port is closed Is the service running and listening? (ss -tulpn)
Handshake works, then the same sequence numbers appear again and again (retransmissions) Packets are lost on the path Check the link, MTU and congestion
Packets arrive, but the application does not answer The network is fine, the program is the problem Application logs, journalctl
No packets seen at all The traffic never arrives on this interface Check the filter, the interface, and what the client is really sending

The meaning of “open”, “closed” and “filtered” is explained in TCP, UDP and ports explained.

Limits you should know

  • Encrypted traffic stays encrypted. For HTTPS, SSH and most modern protocols you can see who talks to whom, when, and how much, but not the contents.
  • Switches only show your traffic. On a modern switched network, tcpdump on a normal host sees its own traffic, not everyone else’s, unless the switch mirrors a port to it.
  • Cost on busy links. Use filters, -c and -w. Avoid -v and name lookups on production servers.
  • Offload can fool you. On virtual machines and modern network cards you may see packets larger than the normal 1500 bytes, or wrong checksums. That is an effect of offloading and is usually harmless.

For the everyday commands to check interfaces and routes before you capture, see Linux networking commands.

Frequently asked questions

Do I need root to run tcpdump?

Yes, normally, because reading raw packets is a privileged operation. Run it with sudo. tcpdump then drops its privileges after opening the interface.

What is the difference between tcpdump and Wireshark?

Both capture and analyse packets. tcpdump is a lightweight command-line tool that suits servers and remote sessions. Wireshark has a graphical interface and deeper analysis. They share the pcap file format, so you can capture with one and open the file in the other.

Can tcpdump show the contents of HTTPS traffic?

No. HTTPS is encrypted, so you see the addresses, ports, timing and sizes, but not the pages. Plain HTTP, DNS and some older protocols can be read.

Why does my capture show nothing?

The most common reasons are the wrong interface, a filter that is too narrow, or traffic that really is not arriving. Try -i any with a broad filter first, then narrow it.

How do I stop tcpdump from filling my disk?

Use -c to limit the number of packets, a filter to limit what is stored, and -C with -W to rotate and cap the size of the capture files.

Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

More tutorials like this

Leave a Comment

Your email address will not be published. Required fields are marked *

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top