When a server experiences mysterious network issues — dropped connections, intermittent timeouts, or suspicious traffic patterns — packet capture is the definitive diagnostic tool. Unlike flow-based monitoring or log analysis, packet capture gives you the raw data: every byte on the wire.
For self-hosted infrastructure, three tools dominate the packet capture landscape: tcpdump, tshark, and termshark. Each serves a different niche, from lightweight CLI filtering to full protocol analysis with a terminal UI. This guide compares them side by side, with practical configurations and Docker deployment examples.
For broader network visibility, see our self-hosted network traffic analysis guide and IDS/IPS comparison.
Why Self-Hosted Packet Capture
Cloud-based packet capture services require routing your traffic through third-party infrastructure — an unacceptable risk for production environments handling sensitive data. Self-hosted packet capture keeps everything on your own servers:
- Complete data sovereignty — no packets leave your network
- Real-time analysis — capture and filter on the live interface without API latency
- Long-term retention — store PCAP files on your own storage with no egress fees
- Integration with your stack — pipe captures directly into your IDS, log aggregation, or alerting pipeline
- Cost control — no per-GB or per-capture charges from cloud providers
Whether you are debugging a TCP handshake failure, investigating a potential intrusion, or profiling API latency, having a reliable packet capture tool on every server is essential.
tcpdump: The Lightweight Classic
tcpdump is the original command-line packet analyzer, available on virtually every Unix-like system. Written in C, it uses libpcap for packet capture and the Berkeley Packet Filter (BPF) for expression-based filtering. It has 3,161 stars on GitHub and is actively maintained (last update: April 2026).
Key Characteristics
- Binary size: ~300 KB — negligible disk footprint
- Dependencies: libpcap only
- Output format: Human-readable text or raw PCAP for offline analysis
- Learning curve: Moderate — BPF syntax is powerful but takes practice
Basic Usage
Capture all traffic on eth0 and save to a file:
| |
Apply a filter to capture only HTTP traffic:
| |
Capture with verbose output and DNS resolution disabled (faster):
| |
Capture the first 100 packets of TCP SYN packets:
| |
Ring Buffer Mode for Continuous Capture
For production servers, use ring buffer mode to prevent disk exhaustion:
| |
This creates 10 files of 100 MB each, rotating every hour. Old files are overwritten automatically.
BPF Filter Quick Reference
| Filter | Description |
|---|---|
host 192.168.1.1 | Traffic to/from specific IP |
net 10.0.0.0/24 | Traffic within a subnet |
port 443 | Traffic on specific port |
tcp portrange 8000-9000 | Traffic in port range |
src host 10.0.0.5 | Traffic from specific source |
dst port 53 | DNS queries going out |
tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 | SYN or FIN packets only |
icmp | All ICMP traffic |
ether host aa:bb:cc:dd:ee:ff | Specific MAC address |
tshark: Wireshark’s Terminal Powerhouse
tshark is the command-line version of Wireshark, the world’s most widely used network protocol analyzer. The Wireshark project has 9,256 stars on GitHub and 1,562 stars on GitLab (primary repository), with active daily development.
tshark supports 3,000+ protocol dissectors — far more than tcpdump. It can decode, analyze, and export protocol fields that tcpdump only sees as raw bytes.
Key Characteristics
- Protocol support: 3,000+ dissectors (HTTP/2, gRPC, TLS, SMB, Kerberos, etc.)
- Output formats: Text, JSON, XML, CSV, PCAP, PDML, PSML
- Statistics: Built-in conversation analysis, endpoint stats, protocol hierarchy
- Decryption: TLS key log file support for decrypting HTTPS traffic
Basic Usage
Capture and display HTTP traffic in real-time:
| |
Export captured data as JSON for programmatic processing:
| |
Generate protocol hierarchy statistics from a capture file:
| |
Analyze a PCAP file for DNS queries:
| |
TLS Decryption
Set the SSLKEYLOGFILE environment variable to decrypt HTTPS traffic:
| |
This requires the client application (browser, curl) to write TLS keys to the same log file.
Statistics Commands
tshark includes powerful built-in statistics that tcpdump cannot match:
| |
termshark: TUI Experience
termshark brings Wireshark’s graphical interface to the terminal. Built in Go, it renders tshark’s output as an interactive TUI with packet lists, details panels, and byte views. It has 9,879 stars on GitHub.
Key Characteristics
- Interface: Full TUI with keyboard navigation (like
htopfor packets) - Rendering: Three-panel layout — packet list, protocol tree, hex/ASCII dump
- Filtering: Live display filters with syntax highlighting
- Dependencies: Requires tshark installed on the system
Installation
| |
Usage
Launch with a live interface:
| |
Open an existing capture file:
| |
Apply a filter from the command line:
| |
Keyboard Shortcuts
| Key | Action |
|---|---|
/ | Enter display filter |
Enter | Apply filter |
Tab | Cycle between panels |
g | Go to packet number |
j/k | Navigate packet list |
q | Quit |
Ctrl+S | Search packets |
Comparison Table
| Feature | tcpdump | tshark | termshark |
|---|---|---|---|
| Stars (GitHub) | 3,161 | 9,256 (mirror) | 9,879 |
| Last Updated | Apr 2026 | Apr 2026 | Apr 2024 |
| Language | C | C | Go |
| Binary Size | ~300 KB | ~15 MB | ~10 MB |
| Protocol Dissectors | Basic (30+) | 3,000+ | 3,000+ (via tshark) |
| Display Filter Syntax | BPF only | Wireshark display filters | Wireshark display filters |
| Capture Filter Syntax | BPF | BPF | BPF |
| JSON Export | No | Yes | No |
| Interactive UI | No | No | Yes (TUI) |
| TLS Decryption | No | Yes | Yes (via tshark) |
| Statistics | Count only | 50+ built-in stats | Via tshark |
| Ring Buffer | Yes | Yes | No |
| Remote Capture | Via SSH pipe | Via SSH pipe | Via SSH pipe |
| Best For | Quick captures, scripts | Deep analysis, exports | Interactive investigation |
Practical Use Cases
Use Case 1: Debugging a Slow HTTP API Response
Use tshark to measure server-side response time:
| |
This shows response time (http.time) for each HTTP response, making it easy to spot slow endpoints.
Use Case 2: Detecting Port Scanning
Use tcpdump’s ring buffer to continuously monitor for SYN scans:
| |
This counts SYN packets per source IP, revealing port scanners.
Use Case 3: Analyzing DNS Exfiltration
Use tshark to find suspiciously long DNS queries:
| |
DNS queries longer than 50 characters may indicate data exfiltration via DNS tunneling. For dedicated DNS traffic analysis, see our DNS traffic analysis guide.
Use Case 4: Capturing Specific Docker Container Traffic
Capture traffic from a specific Docker container by its network namespace:
| |
Docker Deployment
tcpdump Container
Run tcpdump in a privileged container with host network access:
| |
tshark Container
Run tshark with TLS key log support:
| |
termshark Container
For interactive TUI access:
| |
Run with: docker compose run --rm termshark
Choosing the Right Tool
The best choice depends on your workflow:
Use tcpdump when:
- You need the smallest possible footprint (containers, embedded systems)
- You are writing automated scripts or cron-based capture jobs
- You only need basic BPF filtering and PCAP output
- Disk space is limited
Use tshark when:
- You need deep protocol analysis (HTTP/2, gRPC, TLS details)
- You need to export data in structured formats (JSON, CSV)
- You need built-in statistics (endpoints, conversations, protocol hierarchy)
- You need TLS decryption capabilities
Use termshark when:
- You are investigating packets interactively on a remote server
- You want Wireshark’s three-panel view without a GUI
- You need to apply complex display filters on the fly
- You are troubleshooting with a keyboard-only terminal session
In practice, most production setups use all three: tcpdump for automated background capture, tshark for programmatic analysis and export, and termshark for interactive debugging sessions.
FAQ
What is the difference between capture filters and display filters?
Capture filters (BPF syntax) determine which packets are saved to disk. They run at the kernel level and reduce CPU and storage overhead. Display filters (Wireshark syntax) are applied after capture and can reference decoded protocol fields. tcpdump only supports capture filters, while tshark supports both. Use capture filters for production long-term capture to minimize disk usage.
Can I use these tools on a production server without impacting performance?
Yes, with proper configuration. tcpdump with BPF filters has near-zero overhead — the kernel drops unwanted packets before they reach user space. tshark has higher overhead when displaying decoded protocols, but writing raw PCAP output (-w) is efficient. For continuous production capture, use tcpdump ring buffer mode (-C, -W) and analyze PCAP files offline with tshark.
How do I capture traffic from a Docker container?
Use docker exec to run tcpdump inside the container’s network namespace: docker exec <container> tcpdump -i eth0 -w /tmp/capture.pcap. Alternatively, use nsenter to access the container’s network namespace from the host. Both methods require the container to run with CAP_NET_RAW capability.
Can these tools decrypt HTTPS/TLS traffic?
tshark can decrypt TLS traffic if you provide the SSL key log file via -o tls.keylog_file. The client application (browser or curl) must be configured with SSLKEYLOGFILE environment variable to write the session keys. tcpdump and termshark cannot decrypt TLS directly — termshark relies on tshark’s decryption capabilities.
How do I capture on a remote server without installing tools?
Use SSH piping: ssh user@remote 'sudo tcpdump -i eth0 -w - port 80' > local_capture.pcap. This streams the PCAP data over SSH to your local machine, where you can analyze it with Wireshark or tshark. No capture files are written to the remote server’s disk.
What file format should I save captures in?
PCAP (.pcap) is the universal format, readable by all packet analysis tools. PCAPNG (.pcapng) supports additional metadata like interface names and comments but is not supported by older versions of tcpdump. For long-term storage, standard PCAP is recommended for maximum compatibility.