DEV Community

Cover image for How to Use tcpdump for Network Troubleshooting
Lorenzo Fazioli
Lorenzo Fazioli

Posted on Originally published at snorty.space

How to Use tcpdump for Network Troubleshooting

How to Use tcpdump for Network Troubleshooting

tcpdump is one of the most powerful command-line tools for capturing and analyzing network traffic. It is lightweight, fast, and available on most Linux distributions.


Install tcpdump

Ubuntu/Debian:

sudo apt install tcpdump
Enter fullscreen mode Exit fullscreen mode

Fedora:

sudo dnf install tcpdump
Enter fullscreen mode Exit fullscreen mode

Capture Traffic

Capture packets on interface eth0:

sudo tcpdump -i eth0
Enter fullscreen mode Exit fullscreen mode

Capture HTTP Traffic

sudo tcpdump port 80
Enter fullscreen mode Exit fullscreen mode

Only HTTP packets will be displayed.


Capture Traffic from a Specific Host

sudo tcpdump host 192.168.1.50
Enter fullscreen mode Exit fullscreen mode

Useful when troubleshooting communication with a single device.


Save Packets

sudo tcpdump -w capture.pcap
Enter fullscreen mode Exit fullscreen mode

The capture can later be opened in Wireshark.


Read a Capture

tcpdump -r capture.pcap
Enter fullscreen mode Exit fullscreen mode

Filter by Protocol

TCP only:

sudo tcpdump tcp
Enter fullscreen mode Exit fullscreen mode

UDP only:

sudo tcpdump udp
Enter fullscreen mode Exit fullscreen mode

DNS traffic:

sudo tcpdump port 53
Enter fullscreen mode Exit fullscreen mode

Why Use tcpdump?

It is ideal for:

  • Network troubleshooting
  • Malware investigations
  • Security monitoring
  • Learning networking
  • Packet collection

Conclusion

Although Wireshark provides a graphical interface, tcpdump remains the preferred packet capture tool for many Linux administrators because of its speed and flexibility.


Originally published by Lorenzo Fazioli at Snorty.

Top comments (0)