Analyzing network traffic with Tshark
Plumbing the Depths
Without specifying additional parameters, the program displays all data traffic that flows through the selected interface. In some cases, however, you aren't interested in all data and might rather focus on a specific protocol, such as HTTP, Samba, or NFS connections. Tshark can employ various filtering options, and you can combine several of these options for complex filtering scenarios.
In the following scenario, an Apache web server that provides several websites for an intranet is listening on the local system with an IP address of 192.168.0.14 on the eth0 interface. A user on the computer with the IP address 192.168.0.12 reports problems with the connection. You can investigate this problem on the server using the call in the first line of Listing 5.
Listing 5
Checking Traffic
You can restrict the analysis to the eth0
interface using the -i eth0
parameter; specifying host 192.168.0.12
means you will only study packets that run from or to this IP address. The port 80
switch focuses on HTTP traffic, and the keyword and
combines the two parameters, host
and port
.
Figure 3 shows how the HTTP connection is established successfully through a TCP handshake [6]. You'll need to fish the actual HTTP data traffic (frames 10, 13, and 15) out of the substantial output.
Using read filters provides a better overview. Read filters make it possible to restrict the flood of packets using specified criteria. For example, you might only want to monitor the relevant processes in the HTTP protocol (Listing 5, line 2). Figure 4 shows how the network node 102.168.0.12 accesses the site using the HTTP GET
method (frame 16); the web server at the IP address 192.168.0.14 responds with an HTTP status 200 and serves up the page (frames 19, 21, and 22).
The read filter also provides much more powerful possibilities for selecting specific data streams. You can find other examples [7] and detailed descriptions [8] online.
Details
Observing the data flow and subsequent analysis is often enough to troubleshoot problems. In some cases, however, it is necessary to examine the contents of the packages – the payload – in hexadecimal or ASCII form. If the data traffic you are sniffing is unencrypted on the wire, Tshark will display the hexadecimal data with the -x
switch (Listing 5, line 3). Figure 5 shows the output.
The program always considers each package individually, and therefore displays the frames in their own blocks. The example in Figure 5 is the default page that appears after installing an Apache web server on Ubuntu 14.04.
In some cases, it is better to refrain from displaying hexadecimal values for reasons of readability and, instead, expand the output with the text
field. Use the switch combination -T fields -e text
(Listing 5, line 4). Figure 6 shows the website as HTML source code. With very little effort, it is possible to use this output to rebuild a part of the transferred website.
Tips
Tshark provides the necessary default settings to enable fast analysis of data traffic. You can also use Tshark to troubleshoot many protocols and applications. For example, the official Samba wiki recommends the following command to monitor Samba connections:
$ sudo tshark -p -w file_name port 445 or port 139
The -w
switch tells Tshark to write the output not to the console but instead to a file [9] for further processing.
The official Wireshark wiki provides tips for analyzing SMB traffic [10]. You will also find comprehensive instructions for analyzing NFS, SMTP, MySQL, and VoIP, as well as other protocols. In most cases with such searches, you will come across corresponding read filters that you can use to see only the relevant packages.
In this article, I focused on observing wired data traffic. If you also want to use Tshark for analyzing WiFi networks, the comprehensive online documentation will give you some pointers [11]. Tshark can even analyze Bluetooth connections [12] and USB traffic [13].
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
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
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
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.