online posts 16
wireshark 101

task 2.1 · chapter 2 of 8: filters · 25 min

Display filters

objective

Write display filters that pick exactly the right frames out of a busy capture, and learn the one operator, !=, that doesn’t mean what most guides say.

you edit, in the labanswers/2.1.yml

open a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter

given
Capturenone to take: pcaps/mixed.pcapng comes with the lab (64 frames from r1’s switch port)
Try a filterin Wireshark’s filter bar, or tshark -r pcaps/mixed.pcapng -Y 'dns'
Your answersanswers/2.1.yml: one filter per line
new to this? step by stepbeginner
  1. Open /pcaps/mixed.pcapng in Wireshark.
  2. Try dns, ip.addr == 192.168.1.20 and !(ip.addr == 192.168.2.10) in the filter bar; note how many frames each displays.
  3. Challenge: DNS or ARP sent by the laptop; the first packet of each TCP connection.
  4. One filter per line in answers/2.1.yml, then make check T=2.1.

more in meet the lab

1 explain

Hiding what you don’t need

A filter is a question about each frame

Real captures are busy. The one for this task has DNS, ARP, pings, web pages and the switch’s STP messages all mixed together, and that’s from 15 seconds on a quiet network. A display filter is a question Wireshark asks about every frame: is this DNS?, is this from the printer?. Frames that answer yes are shown; the rest are hidden, not deleted. Clear the filter and they’re all back.

in one sentence A display filter hides the frames you don’t want to look at. It never changes the file.

The words a filter is made of

Every line in the packet details pane is a field with a name. Click one and its name appears in the status bar: ip.src, dns.qry.name, tcp.flags.syn. A filter is built from those names:

FilterShows
dnsframes that have a DNS layer at all
ip.src == 192.168.1.20frames whose IP source is the printer
ip.addr == 192.168.1.20frames where the printer is the source or the destination
eth.src == aa:aa:aa:11:11:11frames sent by the laptop’s network card
dns && ip.src == 192.168.1.175both must be true (&& or and)
arp || dnseither one (|| or or)
!(arp)not ARP (! or not)

ip.addr is a shortcut field that matches either address. eth.addr and tcp.port work the same way.

The != trap, and how it changed

Older guides warn you never to write ip.addr != 192.168.2.10, because in old versions of Wireshark it matched frames where either address was different, which is nearly all of them. Wireshark 3.6 changed that. Now != means every address is different, which is what you’d expect. The old meaning is still there if you ever need it, spelled !==.

There’s still one difference left, and it’s the one this task tests. ip.addr != 192.168.2.10 only matches frames that have an IP address. ARP and STP frames have none, so they’re left out too. If you want everything except web’s traffic, write the negation of the positive question:

!(ip.addr == 192.168.2.10)

Not (web is in it) is true for ARP and STP as well, so they stay.

in one sentence x != y needs the field to exist; !(x == y) doesn’t. When in doubt, filter for what you want to hide, then put !( ) round it.

2 show

The filter bar

The filter bar is the long box above the packet list, labeled Apply a display filter. It turns green when the filter makes sense, red when it doesn’t (a typo in a field name, = instead of ==), and yellow when it works but might not mean what you think. Press Enter to apply it.

In the terminal, -Y takes the same filter:

$ tshark -r pcaps/mixed.pcapng -Y 'ip.addr == 192.168.1.20'
   12 1.940422085 192.168.1.20 → 192.168.2.53 ICMP 98 Echo (ping) request  id=0x0924, seq=1/256, ttl=64
   13 1.940563251 192.168.2.53 → 192.168.1.20 ICMP 98 Echo (ping) reply    id=0x0924, seq=1/256, ttl=62 (request in 12)
   15 2.248244168 192.168.1.20 → 192.168.2.53 ICMP 98 Echo (ping) request  id=0x0924, seq=2/512, ttl=64
   ...

A quick way to build one: right-click any field in the details pane, then Apply as Filter › Selected. Wireshark writes the filter for you.

3 follow along

Three filters

  1. In Wireshark, open /pcaps/mixed.pcapng (the reference captures are in /pcaps).

  2. Try each of these in the filter bar. After each, read Displayed in the status bar:

    dns
    ip.addr == 192.168.1.20
    ip.addr != 192.168.2.10
    !(ip.addr == 192.168.2.10)
    

    The last two look the same, but they display different numbers of frames. Clear the filter, then find the frames that only the last one shows: they’re ARP and STP.

  3. Write the three that answer the follow-along questions, one per line:

    editanswers/2.1.ymlCtrl+P → 2.1.yml
    dns: dns
    printer: ip.addr == 192.168.1.20
    not_web: !(ip.addr == 192.168.2.10)
    

    No quotes are needed around the filters. The checker tries each one on pcaps/mixed.pcapng and compares the frames it picks with the right ones, so a different filter that picks exactly the same frames passes too.

4 challenge

Two of your own

  • laptop_dns_or_arp: DNS or ARP frames sent by the laptop. Careful: the laptop’s IP address can change (DHCP), and ARP frames have no IP layer anyway. What’s the one address that’s in every frame the laptop sends?
  • syn_only: the first packet of each TCP connection. It’s the one with the SYN flag set and the ACK flag not set (chapter 6 explains why).
hint

The laptop’s MAC address is aa:aa:aa:11:11:11, in eth.src.

hint

Group with parentheses: (dns || arp) && .... Flags are fields of their own: tcp.flags.syn == 1.

show the solutionanswers/2.1.yml

or pull it into your lab: make solve T=2.1, then git diff --staged shows what changed

laptop_dns_or_arp: (dns || arp) && eth.src == aa:aa:aa:11:11:11
syn_only: tcp.flags.syn == 1 && tcp.flags.ack == 0

Without the parentheses, dns || arp && eth.src == ... means DNS from anyone, or ARP from the laptop (13 frames, not 6): && binds tighter than ||, as × does before + in arithmetic. That’s been the rule since Wireshark 4.0, so a filter written for an older version can behave differently. Parentheses make it the same in every version.

tcp.flags.syn == 1 alone would also match the server’s SYN-ACK, which has both flags set.

5 check: run it, then prove it

$ make check T=2.1

when it's right, you'll see

╭─ task 2.1 · display filters
│  ✓ only DNS (follow along): dns  (12 frames)
│  ✓ everything to or from the printer, 192.168.1.20 (follow along): ...
│  ✓ everything except web's traffic, ARP and STP included (follow along): ...
│  ✓ DNS or ARP sent by the laptop (challenge): ...
│  ✓ only the first packet of each TCP connection (challenge): ...
╰─ 5/5 checks passed  verified