Tshark: The Perfect Combination of tcpdump and Wireshark
When working with networking on Linux, tcpdump is usually the first name that comes to mind. It’s lightweight and available everywhere, but it struggles when you need to dive deep into the application layer to inspect HTTP headers, SQL queries, or SSL/TLS handshakes. In contrast, Wireshark is a heavy-duty analysis powerhouse with a highly intuitive graphical interface. However, you cannot install a Desktop environment on production servers just to inspect packets.
Tshark exists to fill that gap. Essentially, it is the command-line version of Wireshark. It possesses all the power of Wireshark’s dissectors but runs smoothly in the terminal over SSH. After switching to tshark for automation and remote debugging tasks for about six months, I realized this is truly the most essential tool in a systems engineer’s toolkit.
Core differences between the three tools:
- tcpdump: Priority on speed. Best for quick packet captures and basic layer 3-4 filtering (IP, Port).
- Wireshark GUI: Priority on experience. Best for manual analysis of complex TCP streams on a local machine using .pcap files.
- tshark: Priority on depth. Best for Deep Packet Inspection (DPI) directly on the server and automating data extraction into JSON/CSV formats for further processing.
Why I Choose tshark for Production Environments
Here are the reasons why tshark has become the top choice in the real-world projects I’ve deployed:
Advantages
- Dissect packets down to the byte: Tshark understands over 3,000 protocols. You can filter precisely down to individual fields in a DNS packet, which is nearly impossible with tcpdump without complex regex.
- Highly flexible data export: I often use tshark to export data to JSON format, then pipe it directly into an ELK Stack or use Python scripts for automated log parsing.
- Resource efficient: Works perfectly via SSH, eliminating the need to waste bandwidth downloading GB-sized pcap files to a local machine for reading.
- Instant statistics: You can generate HTTP response code statistics or identify the top 10 most active IPs with a single command.
Disadvantages to Consider
- Higher RAM/CPU usage than tcpdump: Because it has to “understand” packet content, tshark consumes more resources. On overloaded servers (CPU > 80%), you should use it with caution.
- Steep learning curve: Distinguishing between Capture Filters (kernel level) and Display Filters (application level) can be confusing at first.
Three Situations Where You Should Ditch the GUI for tshark
Open tshark immediately when you encounter these scenarios:
- Debugging errors on a remote server where the connection bandwidth is too weak to download large
.pcapfiles. - Monitoring specific traffic, for example: capturing all HTTP requests with a 5xx status and logging them separately.
- Quickly extracting a list of domains the server is querying to check for signs of malware or unusual connections.
Deploying tshark: From Installation to Advanced Filtering Techniques
Quick Installation and Configuration
On Ubuntu, the command remains very familiar:
sudo apt update && sudo apt install tshark -y
A small tip: When the installer asks about packet capture permissions for non-privileged users, select Yes. Then add your user to the group to avoid having to use sudo every time:
sudo usermod -aG wireshark $USER
# Don't forget to logout and log back in!
Live Capture
To quickly view traffic on the eth0 interface, use:
tshark -i eth0
If the traffic is too dense, limit it to the first 20 packets to inspect the structure:
tshark -i eth0 -c 20
Advanced Filtering with Display Filters (-Y)
This is tshark’s most powerful weapon. For example, to filter all active HTTP GET requests:
tshark -i eth0 -Y "http.request.method == GET"
Or check if anyone is performing DNS queries for your domain:
tshark -i eth0 -Y "dns.qry.name == itfromzero.com"
Extracting Deep Data with Fields
Instead of reading a chaotic mess, just take what you need. For example: extract source IP, destination IP, and User-Agent:
tshark -i eth0 -n -Y "http.request" -T fields -e ip.src -e ip.dst -e http.user_agent
Note: The -n parameter disables name resolution, helping tshark run significantly faster on high-load systems.
Practical Experience: Troubleshooting Packet Loss in 5 Minutes
I once encountered a difficult debugging case where a microservices system slowed down at 10 AM. Latency spiked from 10ms to 500ms without a clear cause. At that time, the server CPU was hovering around 70%, making it impossible to pull a pcap file locally.
I used tshark to immediately filter for TCP Retransmission packets – the clearest sign of network congestion or packet loss:
tshark -i eth0 -Y "tcp.analysis.retransmission" -T fields -e ip.src -e ip.dst
The result was surprising: nearly 40% of retransmitted traffic was concentrated on an old service calling a database with a timeout of only 50ms. When traffic increased, the DB responded slightly slower, causing this service to continuously resend packets, creating a self-inflicted bottleneck. Thanks to tshark, I identified the correct IP and port after just a few minutes of observation.
Advice: When running in production, use a Capture Filter (parameter -f) to filter out traffic at the kernel level, reducing CPU load:
# Capture only port 443 and look for SSL Handshake errors
tshark -i eth0 -f "tcp port 443" -Y "tls.alert_message"
Tshark is a versatile multi-tool. Once you master the filters, you will find that network administration is no longer a nightmare when incidents occur.

