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 on the eth0 interface. A user on the computer with the IP address 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 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.

Figure 3: The client successfully accesses a website on the intranet.

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 accesses the site using the HTTP GET method (frame 16); the web server at the IP address responds with an HTTP status 200 and serves up the page (frames 19, 21, and 22).

Figure 4: Using the http read filter, Tshark only displays the relevant data.

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.


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.

Figure 5: Tshark will also present many details about data traffic, as required.

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.

Figure 6: You can take a look at each detail of the transmission by pressing just a few buttons.


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].

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Capture File Filtering with Wireshark

    Wireshark doesn’t just work in real time. If you save a history of network activity in a pcap file using a tool such as tcpdump, you can filter the data with Wireshark to search for evidence.

  • Security Lessons

    Building a network flight recorder with Wireshark.

  • Core Technologies

    Learn what's going on in your network, using Linux and its arsenal of packet capture tools.

  • Wireshark

    If you know your way around network protocols, you can get to the source of a problem quickly with Wireshark.

  • FOSSPicks

    This month's FOSSPicks was nearly lost in a stream of AES-256 noise, as Graham struggled to get his encrypted Linux installation (using LUKS) to live alongside an encrypted macOS installation (using APFS).

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95