Dissecting network traffic
wireshark, libpcap, packets, packet sniffer
Building a network flight recorder with Wireshark.
Wireshark [1], the packet sniffer formerly known as Ethereal, is a must-have for system administrators. If you've ever had to troubleshoot a network problem or needed to watch a transaction with a server, then this is the tool for you. Like most (all?) network data capture programs for Linux, Wireshark relies on libpcap, which provides a system-independent interface for capturing packets; therefore, you do not need to write custom routines for every packet sniffer (tcpdump, Snort, Wireshark, etc.). As long as your OS (e.g., Linux, *BSD, HP-UX, Solaris, Windows, etc.) and software support libpcap, you can sniff packets to your heart's content.
Installing libpcap and Wireshark
Libpcap comes with most operating systems, and Wireshark is almost always included (at least on Linux and BSD). Wireshark is sometimes split into two separate packages: one consisting of the back-end utilities like tshark and mergecap, and the other consisting of the graphical user interface (GUI). On Fedora and most related systems, you can simply run yum:
yum install libpcap yum install wireshark-gnome
Debian is just as easy:
apt-get install libpcap0 apt-get install wireshark
One problem with using a vendor-supplied version of Wireshark is that most vendors ship really old versions of Wireshark (e.g., Fedora 11 ships v1.1.3). However, the 1.2 series (and v1.3.0, which might be out by the time this article prints) has a lot of new features, such as protocol support, bug fixes, and GeoIP integration (more on this later). To build Wireshark from source, you'll need to download it, so you can either pull the latest stable version [2], or, if you're feeling brave, you can get one of the latest automated builds from SVN [3]. Once you have unpacked it, the installation is pretty simple:
./configure make make install
To compile Wireshark, you will need to address some dependencies. At a minimum, you'll want libpcap; I also suggest installing GnuTLS, PCRE (Perl-Compatible Regular Expressions), and GeoIP if you want to use any of the advanced features.
Running Wireshark
Unfortunately, to run Wireshark and capture live data, you need to run it as root. Wireshark has had security problems in the past (more on this later) that allow remote attackers to execute code by sending malicious data, which Wireshark processes. Two ways to avoid running Wireshark as root are relatively simple. The first is to use a packet capture program, such as dumpcap or tcpdump, and then later examine the capture files while running Wireshark as a regular user.
The second method is to run Wireshark as root, but within a contained environment. While running Wireshark within a VMware server-based virtual machine, I originally assumed that Wireshark would only see network data to and from that specific virtual machine. Why I thought this isn't clear (just being hopeful, I guess). In fact, because libpcap accesses the kernel and thus the network card at a low enough level, it will see all network traffic to and from that physical interface. Thus, you can run Wireshark in a VM and easily sniff network traffic. The downside of this is that any rogue user with root access to a VM (at least under VMware Server) can see all the network traffic to the underlying physical machine and any guest VM using that interface.
Libpcap Capture Filters
Capturing network traffic on anything but the most quiet of networks is a lot like drinking from a fire hose. The good news is that almost all programs that use libpcap to capture data also accept filter libpcap filter commands (and sometimes, like Wireshark, support their own filters as well). The bad news is that libpcap's filter set is relatively limited, primarily supporting network addresses and ports (because it is protocol aware). At a minimum, you can use it to minimize the amount of data you're writing to the hard drive or forcing Wireshark to process. For example, to capture web traffic in libpcap, you could use the following syntax:
dst port 80 or 443
The tcpdump man page covers libpcap filter syntax in depth.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.