Network

The tcpdump command

Captures and prints the packets that cross a network interface.

Syntax

sudo tcpdump [-i interfaz] [-c N] [-n] [-w archivo | -r archivo] [expresión]Try it in the terminal →

Most useful options

-i interfazListens on that interface. With -i any it listens on all of them at once, on Linux.
-c NStops after capturing N packets. Without this option it runs until you press Ctrl+C.
-nDoes not turn IPs into names through DNS, so output is faster and adds no queries.
-w archivoSaves the packets to a file to analyze later, instead of printing them.
-r archivoReads packets from a previously saved file. It captures nothing, so it does not touch the network.
-APrints each packet's content in ASCII, without the link-level header.

Copy-ready examples

$ sudo tcpdump -i any -c 3 -ncaptures 3 packets from any interface without resolving names.
$ sudo tcpdump -i any -n port 53shows only DNS traffic, which uses port 53.
$ sudo tcpdump -i any -c 100 -w captura.pcapsaves 100 packets to a file so you can analyze them calmly.
$ tcpdump -n -r captura.pcap 'tcp port 443'reads the saved file and filters TCP traffic on port 443. It does not need root.

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Without -c it keeps capturing until you stop it with Ctrl+C; add it so it ends by itself.
  • Without -n it tries to resolve every IP through DNS, which slows the output and adds traffic.
  • Interface names change from machine to machine (eth0, enp3s0, wlan0). List them with tcpdump -D.
  • A filter that is too narrow can leave the capture empty: start with a simple expression and widen it.

Differences from similar commands

  • ss: shows sockets and connections, not packets. It tells you what is listening and what is connected.
  • tshark: is the Wireshark version for the terminal, with more protocol dissectors. tcpdump is lighter.
  • traceroute: shows the route packets take hop by hop. It does not capture your machine's traffic.

Security

A capture can contain passwords and personal data that travel unencrypted, such as HTTP or FTP. Capture only on your own networks or with permission, and delete the .pcap files when you no longer need them.

FAQ

Why does tcpdump ask for administrator rights?

Because it opens the interface and reads frames not addressed to your machine. Linux restricts that to root, or to whoever holds the CAP_NET_RAW capability.

Can it capture passwords?

It can show the content of unencrypted traffic, such as plain HTTP or FTP. HTTPS or SSH traffic is encrypted, so you only see headers and sizes.

How do I open a capture in Wireshark?

Save it with -w file.pcap, then open it in Wireshark, or read it in the terminal with tcpdump -r file.pcap.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course