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.
tcpdump
On 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 tcp
sudo tcpdump udp
sudo tcpdump icmp
sudo tcpdump host 192.168.1.100
sudo tcpdump dst port 80
sudo tcpdump port 22
You 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.
If you run a VPS or dedicated server with Linux, you probably know that managing…
Short summary: Use built-in Linux tools (`who`, `last`, `journalctl`, `/var/log/auth.log`) and optional audit logs to…
Whether you're a new Linux user or a beginner sysadmin, mastering the terminal is a…
Choosing the right Content Management System (CMS) is key when you're building a blog, portfolio,…
Securing your Linux server is a critical task for every sysadmin. One of the simplest…
MegaCLI: useful commands Here are some useful commands: View information about the RAID adapter For…
This website uses cookies.