Free Online Analysis of PCAP Files (Linux)
Get a FREE automated analysis of Packet Capture (PCAP) files, to discover malicious activity, security vulnerabilities and other network events.

Get a FREE automated analysis of Packet Capture (PCAP) files, to discover malicious activity, security vulnerabilities and other network events.
See also: Creating PCAP files on Windows or Mac.
ip route | grep default
to find which
interface has the Default Gateway configured. Take note of the interface's (dev) name.sudo tcpdump -vni <interface-name> -s 0 -w <filename.pcap> -c 100000
If you're using Linux, chances are you already have everything you need to capture network traffic, as most distributions have included these tools since the early '90s. Tcpdump is a command-line network traffic capture and analysis tool that was released in 1988. It is available for most Unix-like operating systems, such as Linux, macOS, FreeBSD, OpenBSD, Solaris, HP-UX, AIX, and OpenWrt (the router OS). Tcpdump uses the libpcap library to capture packets and natively supports the pcap capture format.
If, for some strange reason, you prefer to avoid the command-line interface and your Linux host has a GUI, you can install the Wireshark package to capture network traffic and much more, but that should be the subject of a completely different post.
If you cannot find the tcpdump binary on your Linux system (which might happen inside containers or custom “minimal” server images and distributions), I suggest installing the tool through the native package manager of your operating system:
sudo apt update && sudo apt install tcpdump
sudo yum install tcpdump
sudo pacman -S tcpdump
>Or, if you need the latest possible version, you can install tcpdump from source code on any Linux distribution:
wget https://www.tcpdump.org/release/tcpdump-4.99.4.tar.xz
Note: You can check the parent directory for newer or previous versions.
tar -xvf tcpdump-4.9.3.tar.gz
cd tcpdump-4.99.4.tar.xz
make
sudo make install
To verify tcpdump was/is installed just type tcpdump --help
at the command prompt:
Whether you're already looking at the command prompt or need to launch one (Ctrl + Alt + T should work in most desktop Linux distributions), the next step is to select the network interface you want to 'sniff'. Although tcpdump can capture traffic from all interfaces simultaneously, I strongly advise against this unless the suspected traffic could appear on multiple interfaces. This scenario might occur if you are capturing traffic on a gateway device, but it's unlikely you are running tcpdump on such a device. Gateway devices typically run heavily vendor-customized Linux versions that do not easily grant root permissions.
Type ip route | grep default
to find the device name:
The ip route command lists all routes configured on the host. The default gateway route always starts with the word 'default' followed by the default gateway IP address (e.g., 172.16.0.254) and the local interface (device) that is connected to the same network/subnet (e.g., enp5s0). Under normal circumstances, there should be only one interface for which the default gateway is configured.
If you find no default gateway (which means you cannot route traffic outside) or if you find multiple default gateways configured (which is technically possible but can cause routing conflicts), you will need to pick the desired capture interface on your own.
sudo su
command or simply add sudo before the tcpdump command:sudo tcpdump
.
ls -lh
. A useful trick is to watch the changing file size
until it reaches the desired target using the watch command, like this:
watch 'ls -lh capture.pcap'
. You can stop the capture at any time by pressing
Ctrl + C.
Here’s how I would perform a full-packet capture of 100K packets with tcpdump:
sudo tcpdump -vni <interface-name> -s 0 -w <filename.pcap> -c 100000
Here’s my command with:
You can now verify that the capture was performed correctly by reading and parsing it with the
tcpdump -nr sample.pcap
command. To limit the output to the first 20 packets, you
can use head
-n 20. Alternatively, you can pipe the output to other tools such as
less, which allows you to
scroll through the entire capture, or wc -l, which lets you count the captured
packets.
Voila, we got our forensic-grade pcap capture using tcpdump!
Getting error messages from tcpdump? See this list of Common tcpdump Errors and Solutions.