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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
Kubuntu Focus Announces XE Gen 2 Linux Laptop
Another Kubuntu-based laptop has arrived to be your next ultra-portable powerhouse with a Linux heart.
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.