$linuxjunkies
>

tshark(1)

Capture and analyze network packets from the command line, the non-GUI version of Wireshark.

UbuntuDebianFedoraArch

Synopsis

tshark [OPTIONS] [-i <interface>] [-f <capture filter>] [-Y <display filter>]

Description

tshark is a command-line packet analyzer that captures live network traffic or reads packet files and displays packet details. It's the terminal-based counterpart to Wireshark and supports all the same dissectors and filters for deep packet inspection without a graphical interface.

Use tshark to capture packets for debugging network issues, monitoring traffic, or analyzing saved pcap files. You can filter packets during capture or display, customize output format, and extract specific fields for scripting and automation.

Common options

FlagWhat it does
-i <interface>specify network interface to capture from (e.g., eth0, en0)
-f <capture filter>apply libpcap filter during capture (e.g., -f 'tcp port 80')
-Y <display filter>apply Wireshark display filter to show only matching packets
-r <file>read and analyze packets from a saved pcap file
-w <file>write captured packets to a pcap file
-c <count>capture only specified number of packets then stop
-a duration:<seconds>stop capture after specified duration in seconds
-T fieldsoutput packet data as tab-separated fields
-e <field>specify fields to display (use with -T fields)
-ndisable all name resolution (faster, no DNS/MAC lookups)
-qquiet mode; suppress protocol tree output
-lflush output to stdout after each packet (live output)

Examples

capture live packets on eth0 and display packet summary

tshark -i eth0

capture only HTTPS traffic (port 443) and save to file

tshark -i eth0 -f 'tcp port 443' -w capture.pcap

read pcap file and show only HTTP request packets

tshark -r capture.pcap -Y 'http.request' | head -20

capture and output only source IP, destination IP, and destination port

tshark -i eth0 -T fields -e ip.src -e ip.dst -e tcp.dstport -n

extract DNS query names from a saved capture file

tshark -r capture.pcap -Y 'dns' -e dns.qry.name -T fields

capture up to 100 packets or 30 seconds, whichever comes first

tshark -i wlan0 -c 100 -a duration:30

filter packets for specific IP and output as JSON

tshark -r capture.pcap -Y 'ip.addr==192.168.1.5' -T json > output.json

capture TCP SYN packets in quiet mode with minimal output

sudo tshark -i eth0 -f 'tcp syn' -q

Related commands