↓ Skip to main content
Security

Reading the wire with tshark

In Every packet for my HTTPS request I typed a tshark command full of flags and moved on. This is the post I needed before that one: what each flag does, in the order you reach for them, with the real output. Every example is a script in samarthya/tshark-recipes, so you can run it yourself.
Capture once, read many times: first find the interface with -D, then capture as root with -f, -i, -a and -w into one file, https.pcapng with 28 packets, kept in /tmp and never in git. From that file, five read steps: read with -r, -n and -V; filter with -Y; extract columns with -T fields and -e; summarise with -z; decrypt your own HTTPS with -o tls.keylog_file. Below, the two filter languages: -f, the capture filter, decides what is recorded, in libpcap syntax such as port 53; -Y, the display filter, decides what is shown, using field names such as dns. With several -i, put -f before them.
One capture, many reads

tshark is Wireshark without the window. The manual puts it as “Dump and analyze network traffic”: it captures packets, or reads a saved capture, and prints what it decodes. Because it is a terminal program it works where Wireshark can’t: over SSH, inside WSL, on a server with no screen.

The shape of every session is the same. You capture once, which needs root and a capture filter, into a file. Then you read that file as many times as you like, each time asking a different question. Most of the flags belong to the second half.

Install it
#

DistributionPackageCommandVersion I saw
Oracle Linux, RHEL, Fedorawireshark-clisudo dnf install wireshark-cli3.4.10 on Oracle Linux 9
Debian, Ubuntutsharksudo apt install tshark4.2.2 offered on Ubuntu 24.04

Everything below ran with tshark 3.4.10, inside WSL, on 5 December 2026. I used WSL rather than Windows because the antivirus on my machine answers HTTPS itself, so a capture on Windows wouldn’t show the real server.

The recipes talk to example.com, a name reserved for documentation (RFC 2606, section 3). Their output goes through a small redaction script, so my-machine, my-resolver and xx:xx:xx:xx:xx:xx stand in for my own addresses. More on that at the end.

git clone https://github.com/samarthya/tshark-recipes && cd tshark-recipes

1. What can I capture on?
#

tshark -D lists every interface it can capture from. -i takes the name or the number (manual, -D and -i).

$ sudo bash recipes/01-interfaces.sh

## Interfaces tshark can capture on
$ tshark -D
1. eth0
2. any
3. lo (Loopback)
4. bluetooth-monitor
...

## Which interface reaches the internet
$ wan_if
eth0

## Which interface DNS lookups go out on
$ dns_if
lo

That list came from running it as root. As my normal user, the same command printed something else entirely:

$ tshark -D
1. ciscodump (Cisco remote capture)
2. dpauxmon (DisplayPort AUX channel monitor capture)
3. sdjournal (systemd Journal Export)
4. sshdump (SSH remote capture)
5. udpdump (UDP Listener remote capture)

No eth0, no lo. tshark doesn’t open interfaces itself: it runs a helper, dumpcap, and only root and the wireshark group are allowed to run that one:

$ ls -l /usr/bin/dumpcap
-rwxr-x--- 1 root wireshark 106768 Nov 11 11:14 /usr/bin/dumpcap
$ getcap /usr/bin/dumpcap
/usr/bin/dumpcap cap_net_admin,cap_net_raw=ep

What’s left are extcap helpers, separate programs for special sources such as a remote machine over SSH. The Wireshark wiki says Fedora-family packages “add a wireshark group”, and “you will need to add non-root users to that group in order to capture on local network devices as that user” (CapturePrivileges). On Oracle Linux the wireshark-cli package creates that group when it installs. So either use sudo, or join the group once:

sudo gpasswd -a "$USER" wireshark
newgrp wireshark      # or log in again

After that, tshark -D as my normal user listed eth0, any and lo, and the capture recipes ran without sudo.

Anyone in that group can capture all the traffic on the machine, so add only people who should. Recipe 01 now prints this hint when you’re neither root nor in the group.

The last two answers come from the routing table, not from tshark: ip route get <address> names the interface that packets to that address would leave by, and sends nothing. The second one matters. On WSL the DNS resolver lives on lo, the loopback. If you leave out -i, tshark picks “the first non-loopback interface”, eth0 here, and every DNS lookup is missed. That’s why my first capture for the packet post had no DNS in it. On a machine whose resolver is out on the network, DNS leaves by eth0 like everything else, and -i eth0 alone sees it.

Or capture on any
#

any in that list is Linux’s pseudo-interface for all of them at once. -i any caught the same DNS and HTTPS in one go, 26 packets, already in time order. The price is the link layer: the file’s encapsulation is “Linux cooked-mode capture”, not Ethernet, because, as the Wireshark wiki explains, for the any device libpcap “doesn’t supply the link-layer header for the real ‘hardware protocol’ like Ethernet”. Use any when you want everything quickly, and name interfaces when you want the Ethernet layer, as the packet post does. In the recipes, IFACES=any bash recipes/02-capture.sh switches to it.

2. Capture, with a filter and a stop
#

sudo tshark -q -f "port 53 or tcp port 443" -i eth0 -i lo -a duration:8 -w https-raw.pcapng &
sleep 2; curl -sI https://example.com/ -o /dev/null; wait
FlagWhat it does
-f "port 53 or tcp port 443"capture filter: packets that don’t match are never recorded. port 53 is DNS over UDP or TCP, tcp port 443 is HTTPS
-i eth0 -i lothe interfaces; repeat -i for more than one
-a duration:8autostop after 8 seconds; filesize:N (kB) also works
-w filewrite the raw packets to a file instead of printing them
-qdon’t print the running packet count

Capture filters are written in the libpcap filter language. The full reference is the pcap-filter manual page, where port 53 is true “if the source or the destination TCP/UDP/SCTP port” is 53. The CaptureFilters page of the Wireshark wiki is a list of ready-made ones.

The order of -f and -i matters
#

My first version of this recipe had -f after the -i options. The manual is precise about it: before the first -i, -f “sets the default capture filter expression”. After an -i, it sets the filter “for the interface specified by the last -i option”. The other interfaces are captured unfiltered. A capture file in pcapng format records the filter for each interface, and capinfos -I prints it:

$ capinfos -I https.pcapng | grep -E 'Name =|Filter string'     # -i eth0 -i lo -f "...": wrong
                     Name = eth0
                     Name = lo
                     Filter string = port 53 or tcp port 443

$ capinfos -I https.pcapng | grep -E 'Name =|Filter string'     # -f "..." -i eth0 -i lo: right
                     Name = eth0
                     Filter string = port 53 or tcp port 443
                     Name = lo
                     Filter string = port 53 or tcp port 443

In the wrong version, eth0 had no filter, and an ARP exchange from the virtual network slipped into the file. capinfos is worth knowing on its own: it “reads one or more capture files and returns some or all available statistics” (manual), such as the packet count and duration.

Two interfaces, out of order
#

The first read of that file had DNS packets with negative times, because each interface is buffered separately and the packets reach the file out of time order. reordercap rewrites a capture “with the frames sorted by increasing timestamp” (manual):

$ reordercap https-raw.pcapng https.pcapng
28 frames, 1 out of order

3. Read it
#

-r reads a file instead of a live interface, and -n turns off name resolution, so you see addresses and port numbers, not names. One line per packet (I cut the TCP timestamp fields from the ends of the lines):

$ tshark -r https.pcapng -n
    1 0.000000000 my-resolver → my-resolver DNS 71 Standard query 0x6925 A example.com
    2 0.000039954 my-resolver → my-resolver DNS 71 Standard query 0xca27 AAAA example.com
    3 0.024554524 my-resolver → my-resolver DNS 127 Standard query response 0xca27 AAAA example.com AAAA 2606:4700:10::ac42:93f3 ...
    4 0.028212727 my-resolver → my-resolver DNS 103 Standard query response 0x6925 A example.com A 172.66.147.243 A 104.20.23.154
    5 0.029153607 my-machine → 172.66.147.243 TCP 74 48334 → 443 [SYN] Seq=0 Win=64480 Len=0 MSS=1240 SACK_PERM=1
    6 0.067293350 172.66.147.243 → my-machine TCP 74 443 → 48334 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1400 SACK_PERM=1
    7 0.067380904 my-machine → 172.66.147.243 TCP 66 48334 → 443 [ACK] Seq=1 Ack=1 Win=64512 Len=0
    8 0.074255463 my-machine → 172.66.147.243 TLSv1 583 Client Hello
...
   27 0.156743687 172.66.147.243 → my-machine TCP 66 443 → 48334 [FIN, ACK] Seq=4738 Ack=848 Win=131072 Len=0
   28 0.156780596 my-machine → 172.66.147.243 TCP 66 48334 → 443 [ACK] Seq=848 Ack=4739 Win=79360 Len=0

The columns are: packet number, seconds since the first packet, source → destination, protocol, length in bytes, and a one-line summary. The DNS lines show the resolver on both sides: it sits on lo, and a packet to a local address leaves from that same address.

To see one packet in full, add -V. On its own it expands every layer; -O tcp expands only TCP “and show[s] only the top-level detail line for all other protocols”. So the Ethernet and IP layers take one line each:

$ tshark -r https.pcapng -n -Y 'tcp.flags.syn == 1 && tcp.flags.ack == 0' -V -O tcp
Frame 5: 74 bytes on wire (592 bits), 74 bytes captured (592 bits) on interface eth0, id 0
Ethernet II, Src: xx:xx:xx:xx:xx:xx, Dst: xx:xx:xx:xx:xx:xx
Internet Protocol Version 4, Src: my-machine, Dst: 172.66.147.243
Transmission Control Protocol, Src Port: 48334, Dst Port: 443, Seq: 0, Len: 0
    Source Port: 48334
    Destination Port: 443
    [Stream index: 0]
    ...
    Flags: 0x002 (SYN)
    ...
        .... .... ..1. = Syn: Set
    ...
    Window: 64480
    ...
        TCP Option - Maximum segment size: 1240 bytes

Anything in [square brackets] isn’t in the packet: it’s something tshark worked out, such as the stream index, the number it gives each TCP connection.

4. Narrow it down: display filters
#

A display filter (-Y) decides what is shown, not what was recorded, so you can try as many as you like on the same file. It is a different language from the capture filter: it uses the field names you see in the -V output. The wireshark-filter manual has the syntax, and the display filter reference lists every field.

I wantDisplay filter
DNS onlydns
new TCP connectionstcp.flags.syn == 1 && tcp.flags.ack == 0
TLS ClientHellostls.handshake.type == 1
retransmissions, duplicate ACKs, out-of-ordertcp.analysis.flags
how each connection endedtcp.flags.fin == 1 || tcp.flags.reset == 1
$ tshark -r https.pcapng -n -Y 'tls.handshake.type == 1'
    8 0.074255463 my-machine → 172.66.147.243 TLSv1 583 Client Hello

tcp.analysis.flags printed nothing on this capture, which is good news: no TCP trouble. On my first attempt it would have found plenty: that capture had two retransmissions (one of them my ClientHello), four duplicate ACKs and an out-of-order segment, all in the first half-second.

Capture filter -fDisplay filter -Y
Whenwhile capturingwhile reading
What doesn’t matchis never recordedis only hidden
Languagelibpcap: port 53 or tcp port 443field names: tls.handshake.type == 1
Referencepcap-filterwireshark-filter

5. Only the columns you want
#

-T fields prints just the fields you name with -e, separated by tabs. -E header=y adds a header line, and -E separator=, turns it into CSV. The field names are the same ones display filters use.

$ tshark -r https.pcapng -n -Y 'dns.flags.response == 1' -T fields -E header=y \
    -e dns.qry.name -e dns.qry.type -e dns.a -e dns.aaaa
dns.qry.name	dns.qry.type	dns.a	dns.aaaa
example.com	28		2606:4700:10::ac42:93f3,2606:4700:10::6814:179a
example.com	1	172.66.147.243,104.20.23.154

$ tshark -r https.pcapng -n -Y 'tls.handshake.type == 1' -T fields -E header=y \
    -e ip.dst -e tls.handshake.extensions_server_name -e tls.handshake.extensions_alpn_str
ip.dst	tls.handshake.extensions_server_name	tls.handshake.extensions_alpn_str
172.66.147.243	example.com	h2,http/1.1

Type 1 is an A record (IPv4), type 28 an AAAA (IPv6). The second command answers a question people often get wrong: HTTPS doesn’t hide which site you visit. The site name travels in the clear in the ClientHello, in the Server Name Indication (SNI) extension. So does the list of protocols curl offered (ALPN): HTTP/2 first.

6. Summaries instead of packets
#

-q suppresses the packets, and -z asks for a statistic at the end (manual, -z):

$ tshark -r https.pcapng -n -q -z io,phs
===================================================================
Protocol Hierarchy Statistics
Filter:

eth                                      frames:28 bytes:7567
  ip                                     frames:28 bytes:7567
    udp                                  frames:4 bytes:372
      dns                                frames:4 bytes:372
    tcp                                  frames:24 bytes:7195
      tls                                frames:10 bytes:3787
        tcp.segments                     frames:1 bytes:375
===================================================================

$ tshark -r https.pcapng -n -q -z conv,tcp
                                                    |       <-      | |       ->      | |     Total     |
my-machine:48334  <-> 172.66.147.243:443             11 5,483bytes      13 1,712bytes      24 7,195bytes

The protocol hierarchy is the shape of the whole capture at a glance. Only 10 of the 24 TCP packets carried TLS; the rest were bare acknowledgements and the handshake. conv,tcp gives one row per connection, with packets and bytes each way (I cut the start and duration columns): 5,483 bytes came in for a request with no page body. -z endpoints,ip lists every address instead.

7. Follow a conversation, and see why HTTPS matters
#

-z follow,tcp,ascii,0 rebuilds TCP stream 0 from its packets and prints both directions as text. Data from the second side “is prefixed with a tab”. Over plain HTTP (recipe 07 captures its own request to http://example.com/), it reads like a chat log:

$ tshark -r http.pcapng -n -q -z follow,tcp,ascii,0
Follow: tcp,ascii
Filter: tcp.stream eq 0
Node 0: my-machine:57964
Node 1: 172.66.147.243:80
75
GET / HTTP/1.1
Host: example.com
User-Agent: curl/7.76.1
Accept: */*

	928
HTTP/1.1 200 OK
Date: Sat, 05 Dec 2026 20:51:38 GMT
Content-Type: text/html; charset=utf-8
...

The numbers (75, 928) are the bytes in each chunk. The same command on the HTTPS capture:

$ tshark -r https.pcapng -n -q -z follow,tcp,ascii,0
Node 0: my-machine:48334
Node 1: 172.66.147.243:443
517
..............[N.
.9pU......,...'......).z. zo.&6...b..R\.)T.A...t.`.MA...}..F.........,.0.......+./...#.'.
...............=.<.5./...........k.g.9.3...m..............example.com.........
........................3t.........h2.http/1.1.........1....".  ...

That’s the ClientHello, and the only readable words are the site name and h2.http/1.1: the SNI and ALPN from step 5. Everything after it is encrypted.

8. Decrypt your own HTTPS
#

curl, like Firefox and Chrome, writes the TLS session secrets to the file named in SSLKEYLOGFILE so that Wireshark “can decrypt them” (everything curl). -o sets any tshark preference for one run; tls.keylog_file is where the secrets are (Wireshark wiki, TLS).

$ SSLKEYLOGFILE=keys.log curl -sI https://example.com/ -o /dev/null      # while capturing to tls.pcapng

$ tshark -r tls.pcapng -n -Y 'tls.record.opaque_type == 23' | head -3            # without the keys
    7 0.051120494 172.66.147.243 → my-machine TLSv1.3 374 Application Data
   10 0.053082205 my-machine → 172.66.147.243 TLSv1.3 146 Change Cipher Spec, Application Data
   11 0.053207459 my-machine → 172.66.147.243 TLSv1.3 161 Application Data, Application Data

$ tshark -r tls.pcapng -n -o tls.keylog_file:keys.log -Y 'http2.type == 1' -V -O http2 | grep -E '^ +Header: '
        Header: :method: HEAD
        Header: :path: /
        Header: :scheme: https
        Header: :authority: example.com
        Header: user-agent: curl/7.76.1
        Header: accept: */*
        Header: :status: 200 OK
        Header: date: Sat, 05 Dec 2026 20:52:38 GMT
        Header: content-type: text/html; charset=utf-8
        Header: server: cloudflare
        ...

http2.type == 1 means HEADERS frames, “type=0x01” in RFC 9113, section 6.2. One field name tripped me up: my first filter, tls.record.content_type == 23, matched nothing. In TLS 1.3 the real record type is encrypted, and every record says “application data” on the outside; tshark files that outer label under tls.record.opaque_type (field reference).

Anyone holding the key log can read the session, so recipe 08 deletes it when it exits.

9. What does this command talk to?
#

The recipe I’ll use most puts the others together: capture everything except SSH while any command runs, then list the names it looked up, the sites it opened TLS connections to, and every conversation.

$ sudo bash recipes/09-watch-a-command.sh dnf -q makecache --refresh
running: dnf -q makecache --refresh

## Names looked up (DNS)
      8 yum.oracle.com
      8 dl.google.com

## Sites it opened TLS connections to (SNI)
      1 dl.google.com	64.233.180.136
      3 dl.google.com	64.233.180.93
      4 yum.oracle.com	23.51.230.156

I expected Oracle’s servers. I didn’t expect Google. grep -l dl.google.com /etc/yum.repos.d/*.repo found the answer: google-chrome.repo. Google Chrome is installed in this WSL distro, and its repository is checked every time the package manager refreshes. Nothing wrong with it, but I’d forgotten it was there, and the packets remembered.

It sees the whole machine during that time, not just your command, so run it when little else is going on.

Keeping a capture private
#

A capture file holds your IP and MAC addresses, the names you looked up, and anything sent unencrypted, cookies included. The repo is built so none of that leaks by accident:

  • Captures stay out of git. They go to /tmp/tshark-recipes-<your user id>, and .gitignore blocks *.pcap* and *.log anyway. Once a capture is pushed, deleting the file doesn’t take it out of the history.
  • Output is redacted. lib/redact.sh replaces this machine’s addresses, its resolver and gateway, every MAC address and the DNS search domain. tshark prints MAC addresses as Vendor_xx:xx:xx too, which keeps the last three bytes, so it covers that form as well. Pipe your own output through it: tshark -r file.pcapng | lib/redact.sh.
  • The TLS key log is deleted when recipe 08 exits.

Quick reference
#

FlagMeaning
-Dlist the interfaces
-i <name or number>capture on this interface; repeat for more
-f "<filter>"capture filter (libpcap); put it before the -i options
-a duration:Nstop after N seconds
-w <file>write packets to a file
-r <file>read packets from a file
-nno name resolution
-Y "<filter>"display filter (field names)
-V, -O <protocols>full detail; only for these protocols
-T fields -e <field>print only these fields; -E header=y, -E separator=,
-q -z <statistic>statistics only: io,phs, conv,tcp, endpoints,ip, follow,tcp,ascii,0
-o tls.keylog_file:<file>decrypt TLS with a key log

Keywords
#

TermMeaning
tsharkWireshark’s command-line version: captures or reads packets and prints them decoded
pcapngthe capture file format tshark writes; it records each interface, and its capture filter
Capture filter-f, libpcap syntax; decides what is recorded
Display filter-Y, Wireshark field names; decides what is shown
Loopback (lo)the interface for traffic a machine sends to itself; on WSL the DNS resolver is there
SNIServer Name Indication: the site name, sent unencrypted in the TLS ClientHello
ALPNthe TLS extension where client and server agree on HTTP/2 or HTTP/1.1
Key logthe file of TLS session secrets that lets tshark decrypt a session; treat it like a password

Takeaways
#

  • Capture once, read many times: the capture filter decides what you keep, display filters ask the questions.
  • Only extcap helpers in tshark -D? That’s permissions: use sudo or the wireshark group.
  • Name your interfaces. The default skips loopback, and on WSL that’s where DNS goes.
  • With several -i, put -f first; capinfos -I shows which interface got which filter.
  • -T fields -e and -z turn a capture into answers; recipe 09 shows a command’s names, sites and connections.
  • A capture is personal data: keep it out of git and redact before you share.

References
#

On this blog: Every packet for my HTTPS request uses these on one request to GitHub, and the Handshake update reads a TLS 1.3 handshake field by field.

Author
Samarthya
Engineer, learner, tinkerer. This is my trophy shelf of everyday work and leisure.

Related

The padlock's new rulebook

·5 mins
The padlock in your browser follows a rulebook. In July 2026 that rulebook got a new edition. Almost nobody noticed, and that was the point. Same version, new edition What’s an RFC? # The internet runs on agreements. When my machine talks to a website, both sides follow the same written rules, or the conversation falls apart. Those rules are published as numbered documents called RFCs. You don’t edit an old one in place: a new RFC with a new number is published, and the old page gets a banner saying “This RFC is now obsolete”. That’s exactly what happened to TLS 1.3 this year.

My antivirus answered for GitHub

··7 mins
I wrote a small program to check whether GitHub already uses post-quantum key exchange. It said yes. I was about to write that down as a fact when a different tool gave me a different answer, and the reason was sitting on my own machine. Two connections, one of them hidden A result that looked too good # While writing about the locks I use without noticing I wanted one line of evidence: which key exchange does a real site use today? Go makes that easy. Since Go 1.25 a connection reports the key-exchange group it used, and Python can do the same since 3.15, so this is the whole program in either:

The locks I use without noticing

··9 mins
I type gh pr list dozens of times a day. The answer comes back in under a second from a server I’ve never met, and nobody in between can read it or change it. One evening I got curious about what actually happens in that second. Three jobs, four families Following one command onto the wire # First, where does gh go? Its debug switch shows every request: