As a Linux system administrator, understanding what happens on your network is crucial. One of the most powerful tools to monitor network traffic directly from the command line is tcpdump. Itās lightweight, pre-installed on many distros, and extremely versatile for capturing and analyzing packets.
In this guide, weāll walk through what tcpdump is, how to use it, and practical examples tailored for beginner sysadmins.
tcpdump?tcpdump is a command-line packet analyzer. It allows you to capture and display network packets transmitted over a network interface. It works by using the libpcap library to sniff and filter traffic.
Itās like a real-time log of the conversations your server is having on the network ā and youāre invited to listen in.
tcpdumpOn most distributions, itās available via the default package manager:
bashCopyEdit# Debian/Ubuntu
sudo apt install tcpdump
# RHEL/CentOS/AlmaLinux
sudo dnf install tcpdump
# Arch Linux
sudo pacman -S tcpdump
You can verify installation with:
bashCopyEdittcpdump --version
To capture packets on your default network interface:
bashCopyEditsudo tcpdump
Youāll see a flood of real-time traffic. Use Ctrl + C to stop capturing.
To list available interfaces:
bashCopyEdittcpdump -D
To capture on a specific one:
bashCopyEditsudo tcpdump -i eth0
sudo tcpdump tcpsudo tcpdump udpsudo tcpdump icmpsudo tcpdump host 192.168.1.100sudo tcpdump dst port 80sudo tcpdump port 22You can save output to a .pcap file for later analysis with tools like Wireshark:
bashCopyEditsudo tcpdump -i eth0 -w capture.pcap
To read the file:
bashCopyEditsudo tcpdump -r capture.pcap
Use the -c option to avoid overwhelming output:
bashCopyEditsudo tcpdump -c 10
To make packet contents easier to understand:
bashCopyEditsudo tcpdump -n -v
-n: Donāt resolve hostnames.-v: Verbose output (use -vv or -vvv for more detail).bashCopyEditsudo tcpdump -i eth0 dst port 80
bashCopyEditsudo tcpdump -i eth0 port 22
bashCopyEditsudo tcpdump -i eth0 host 10.0.0.50
tcpdump with sudo to access network interfaces.tcpdump running unattended ā it can quickly consume disk space.screen or tmux if running remotely.tcpdump is an essential tool in every Linux sysadminās toolkit. Whether youāre diagnosing a network issue, checking for suspicious traffic, or just learning how networking works ā itās a great place to start.
As you grow, you can combine tcpdump with tools like awk, grep, or Wireshark to do even deeper analysis.
As a Linux System Administrator, mastering the command line is key to efficiently managing servers,…
Introduction WireGuard is a fast, lightweight, and modern VPN protocol designed for simplicity and performance.If…
Securing your website with HTTPS is essential for privacy, SEO ranking, and user trust. Letās…
If you manage Linux servers regularly, you know how important SSH (Secure Shell) is. Whether…
If youāre new to Linux or thinking about switching from Windows or macOS, this guide…
Introduction Site Reliability Engineering (SRE) has become a critical discipline in modern IT operations. The…
This website uses cookies.