Skip to content

Capture filters and display filters

Module
Your First Packet Capture
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS, netlab 1.0, GNU Bash 5.2.21, tcpdump 4.99.4; course VM Ubuntu 24.04.4 LTS with Wireshark 4.2.2
Prerequisites
On this page

A large capture can contain thousands of frames when you want one short web exchange. You can reduce the recording, or keep it and reduce the visible rows. Those choices look similar on screen but leave different evidence. By the end, you can choose between them and write both kinds of filter.

Keep the lab in its starting state. Open two terminals on laptop with netlab shell laptop, starting in the shared home directory. Use the saved-file workflow from Reading a capture as text. Start listening before generating traffic, answer sudo’s password question, and stop the listener with Ctrl+C after terminal 2 finishes.

First, omit the words after the output filename. A capture filter decides which frames are recorded. This run has no capture filter, so it keeps traffic that the earlier web-only filter would exclude. The capture point is still only laptop:eth0; removing a filter does not let it observe every other interface.

Terminal 2 runs ping to phone and then requests hello.txt from web. Here -c 2 limits ping to two requests. That option belongs to ping; it does not limit the listening tcpdump. These are two different programs with their own options.

Record without a capture filter
learner@laptop:~$ sudo tcpdump -i eth0 -n -w all.pcap[sudo] password for learner: tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes^C20 packets captured
20 packets received by filter
0 packets dropped by kernellearner@laptop:~$ tcpdump -n -r all.pcapreading from file all.pcap, link-type EN10MB (Ethernet), snapshot length 262144
11:57:07.808148 ARP, Request who-has 10.77.10.11 tell 10.77.10.10, length 28
11:57:07.808195 ARP, Reply 10.77.10.11 is-at 02:77:10:00:00:11, length 28
11:57:07.808197 IP 10.77.10.10 > 10.77.10.11: ICMP echo request, id 167, seq 1, length 64
11:57:07.808218 IP 10.77.10.11 > 10.77.10.10: ICMP echo reply, id 167, seq 1, length 64
11:57:08.828932 IP 10.77.10.10 > 10.77.10.11: ICMP echo request, id 167, seq 2, length 64
11:57:08.828996 IP 10.77.10.11 > 10.77.10.10: ICMP echo reply, id 167, seq 2, length 64
11:57:09.336193 ARP, Request who-has 10.77.10.1 tell 10.77.10.10, length 28
11:57:09.336245 ARP, Reply 10.77.10.1 is-at 02:77:10:00:00:01, length 28
11:57:09.336247 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [S], seq 3290426603, win 64240, options [mss 1460,sackOK,TS val 1618208793 ecr 0,nop,wscale 10], length 0
11:57:09.336291 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [S.], seq 1656168547, ack 3290426604, win 65160, options [mss 1460,sackOK,TS val 3478611042 ecr 1618208793,nop,wscale 10], length 0
11:57:09.336300 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [.], ack 1, win 63, options [nop,nop,TS val 1618208793 ecr 3478611042], length 0
11:57:09.336362 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [P.], seq 1:84, ack 1, win 63, options [nop,nop,TS val 1618208793 ecr 3478611042], length 83: HTTP: GET /hello.txt HTTP/1.1
11:57:09.336380 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [.], ack 84, win 64, options [nop,nop,TS val 3478611042 ecr 1618208793], length 0
11:57:09.339841 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [P.], seq 1:173, ack 84, win 64, options [nop,nop,TS val 3478611046 ecr 1618208793], length 172: HTTP: HTTP/1.0 200 OK
11:57:09.339885 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [.], ack 173, win 63, options [nop,nop,TS val 1618208797 ecr 3478611046], length 0
11:57:09.339919 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [P.], seq 173:189, ack 84, win 64, options [nop,nop,TS val 3478611046 ecr 1618208797], length 16: HTTP
11:57:09.339921 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [.], ack 189, win 63, options [nop,nop,TS val 1618208797 ecr 3478611046], length 0
11:57:09.339952 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [F.], seq 189, ack 84, win 64, options [nop,nop,TS val 3478611046 ecr 1618208797], length 0
11:57:09.340037 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [F.], seq 84, ack 190, win 63, options [nop,nop,TS val 1618208797 ecr 3478611046], length 0
11:57:09.340158 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [.], ack 85, win 64, options [nop,nop,TS val 3478611046 ecr 1618208797], length 0learner@laptop:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Terminal 1 records all.pcap without a capture filter, then reads it back after stopping.
Steps (12)
  1. Type sudo tcpdump -i eth0 -n -w all.pcap
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
  7. Terminal 2 on laptop finished sending. Return to terminal 1 and press Ctrl+C to stop listening.
  8. Press Ctrl + C
  9. Output: 20 packets captured 20 packets received by filter 0 packets dropped by kernel
  10. Type tcpdump -n -r all.pcap
  11. Press Enter
  12. Output: reading from file all.pcap, link-type EN10MB (Ethernet), snapshot length 262144 11:57:07.808148 ARP, Request who-has 10.77.10.11 tell 10.77.10.10, length 28 11:57:07.808195 ARP, Reply 10.77.10.11 is-at 02:77:10:00:00:11, length 28 11:57:07.808197 IP 10.77.10.10 > 10.77.10.11: ICMP echo request, id 167, seq 1, length 64 11:57:07.808218 IP 10.77.10.11 > 10.77.10.10: ICMP echo reply, id 167, seq 1, length 64 11:57:08.828932 IP 10.77.10.10 > 10.77.10.11: ICMP echo request, id 167, seq 2, length 64 11:57:08.828996 IP 10.77.10.11 > 10.77.10.10: ICMP echo reply, id 167, seq 2, length 64 11:57:09.336193 ARP, Request who-has 10.77.10.1 tell 10.77.10.10, length 28 11:57:09.336245 ARP, Reply 10.77.10.1 is-at 02:77:10:00:00:01, length 28 11:57:09.336247 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [S], seq 3290426603, win 64240, options [mss 1460,sackOK,TS val 1618208793 ecr 0,nop,wscale 10], length 0 11:57:09.336291 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [S.], seq 1656168547, ack 3290426604, win 65160, options [mss 1460,sackOK,TS val 3478611042 ecr 1618208793,nop,wscale 10], length 0 11:57:09.336300 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [.], ack 1, win 63, options [nop,nop,TS val 1618208793 ecr 3478611042], length 0 11:57:09.336362 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [P.], seq 1:84, ack 1, win 63, options [nop,nop,TS val 1618208793 ecr 3478611042], length 83: HTTP: GET /hello.txt HTTP/1.1 11:57:09.336380 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [.], ack 84, win 64, options [nop,nop,TS val 3478611042 ecr 1618208793], length 0 11:57:09.339841 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [P.], seq 1:173, ack 84, win 64, options [nop,nop,TS val 3478611046 ecr 1618208793], length 172: HTTP: HTTP/1.0 200 OK 11:57:09.339885 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [.], ack 173, win 63, options [nop,nop,TS val 1618208797 ecr 3478611046], length 0 11:57:09.339919 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [P.], seq 173:189, ack 84, win 64, options [nop,nop,TS val 3478611046 ecr 1618208797], length 16: HTTP 11:57:09.339921 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [.], ack 189, win 63, options [nop,nop,TS val 1618208797 ecr 3478611046], length 0 11:57:09.339952 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [F.], seq 189, ack 84, win 64, options [nop,nop,TS val 3478611046 ecr 1618208797], length 0 11:57:09.340037 IP 10.77.10.10.49054 > 10.77.20.80.80: Flags [F.], seq 84, ack 190, win 63, options [nop,nop,TS val 1618208797 ecr 3478611046], length 0 11:57:09.340158 IP 10.77.20.80.80 > 10.77.10.10.49054: Flags [.], ack 85, win 64, options [nop,nop,TS val 3478611046 ecr 1618208797], length 0
Send traffic from terminal 2 on laptop
learner@laptop:~$ ping -c 2 10.77.10.11PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data.
64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.142 ms
64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.092 ms

--- 10.77.10.11 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1021ms
rtt min/avg/max/mdev = 0.092/0.117/0.142/0.025 mslearner@laptop:~$ curl -sS http://10.77.20.80/hello.txtHello from web.learner@laptop:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Terminal 2 pings phone and requests hello.txt while all.pcap is being recorded.
Steps (6)
  1. Type ping -c 2 10.77.10.11
  2. Press Enter
  3. Output: PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data. 64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.142 ms 64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.092 ms --- 10.77.10.11 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1021ms rtt min/avg/max/mdev = 0.092/0.117/0.142/0.025 ms
  4. Type curl -sS http://10.77.20.80/hello.txt
  5. Press Enter
  6. Output: Hello from web.

The read-back has 20 frame lines: four for the ping exchange, twelve for the TCP web exchange, and four for address lookups. Ethernet and Local Delivery explains those address lookups. You do not need to read their fields yet. Keep them so you can return to them later.

The capture expression host 10.77.20.80 keeps traffic to or from web’s address. It does not mean only traffic sent by that machine. The earlier tcp port 80 expression keeps TCP traffic with that port at either end.

A display filter chooses which already-recorded frames are shown, without changing the file.

Predict: after capturing only one address, can a display filter recover the ping exchange with phone?

Record only traffic involving web
learner@laptop:~$ sudo tcpdump -i eth0 -n -w web.pcap host 10.77.20.80[sudo] password for learner: tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes^C12 packets captured
12 packets received by filter
0 packets dropped by kernellearner@laptop:~$ tcpdump -n -r web.pcapreading from file web.pcap, link-type EN10MB (Ethernet), snapshot length 262144
11:57:37.973511 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [S], seq 3360053108, win 64240, options [mss 1460,sackOK,TS val 1136351580 ecr 0,nop,wscale 10], length 0
11:57:37.973544 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [S.], seq 1908834339, ack 3360053109, win 65160, options [mss 1460,sackOK,TS val 2974170415 ecr 1136351580,nop,wscale 10], length 0
11:57:37.973564 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [.], ack 1, win 63, options [nop,nop,TS val 1136351580 ecr 2974170415], length 0
11:57:37.973632 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [P.], seq 1:84, ack 1, win 63, options [nop,nop,TS val 1136351580 ecr 2974170415], length 83: HTTP: GET /hello.txt HTTP/1.1
11:57:37.973649 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [.], ack 84, win 64, options [nop,nop,TS val 2974170415 ecr 1136351580], length 0
11:57:37.976257 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [P.], seq 1:173, ack 84, win 64, options [nop,nop,TS val 2974170418 ecr 1136351580], length 172: HTTP: HTTP/1.0 200 OK
11:57:37.976327 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [.], ack 173, win 63, options [nop,nop,TS val 1136351583 ecr 2974170418], length 0
11:57:37.976374 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [P.], seq 173:189, ack 84, win 64, options [nop,nop,TS val 2974170418 ecr 1136351583], length 16: HTTP
11:57:37.976387 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [.], ack 189, win 63, options [nop,nop,TS val 1136351583 ecr 2974170418], length 0
11:57:37.976435 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [F.], seq 189, ack 84, win 64, options [nop,nop,TS val 2974170418 ecr 1136351583], length 0
11:57:37.976450 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [F.], seq 84, ack 190, win 63, options [nop,nop,TS val 1136351583 ecr 2974170418], length 0
11:57:37.976521 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [.], ack 85, win 64, options [nop,nop,TS val 2974170418 ecr 1136351583], length 0learner@laptop:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Terminal 1 records web.pcap with a host capture filter, then reads the narrower file.
Steps (12)
  1. Type sudo tcpdump -i eth0 -n -w web.pcap host 10.77.20.80
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
  7. Terminal 2 on laptop finished sending. Return to terminal 1 and press Ctrl+C to stop listening.
  8. Press Ctrl + C
  9. Output: 12 packets captured 12 packets received by filter 0 packets dropped by kernel
  10. Type tcpdump -n -r web.pcap
  11. Press Enter
  12. Output: reading from file web.pcap, link-type EN10MB (Ethernet), snapshot length 262144 11:57:37.973511 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [S], seq 3360053108, win 64240, options [mss 1460,sackOK,TS val 1136351580 ecr 0,nop,wscale 10], length 0 11:57:37.973544 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [S.], seq 1908834339, ack 3360053109, win 65160, options [mss 1460,sackOK,TS val 2974170415 ecr 1136351580,nop,wscale 10], length 0 11:57:37.973564 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [.], ack 1, win 63, options [nop,nop,TS val 1136351580 ecr 2974170415], length 0 11:57:37.973632 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [P.], seq 1:84, ack 1, win 63, options [nop,nop,TS val 1136351580 ecr 2974170415], length 83: HTTP: GET /hello.txt HTTP/1.1 11:57:37.973649 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [.], ack 84, win 64, options [nop,nop,TS val 2974170415 ecr 1136351580], length 0 11:57:37.976257 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [P.], seq 1:173, ack 84, win 64, options [nop,nop,TS val 2974170418 ecr 1136351580], length 172: HTTP: HTTP/1.0 200 OK 11:57:37.976327 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [.], ack 173, win 63, options [nop,nop,TS val 1136351583 ecr 2974170418], length 0 11:57:37.976374 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [P.], seq 173:189, ack 84, win 64, options [nop,nop,TS val 2974170418 ecr 1136351583], length 16: HTTP 11:57:37.976387 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [.], ack 189, win 63, options [nop,nop,TS val 1136351583 ecr 2974170418], length 0 11:57:37.976435 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [F.], seq 189, ack 84, win 64, options [nop,nop,TS val 2974170418 ecr 1136351583], length 0 11:57:37.976450 IP 10.77.10.10.44768 > 10.77.20.80.80: Flags [F.], seq 84, ack 190, win 63, options [nop,nop,TS val 1136351583 ecr 2974170418], length 0 11:57:37.976521 IP 10.77.20.80.80 > 10.77.10.10.44768: Flags [.], ack 85, win 64, options [nop,nop,TS val 2974170418 ecr 1136351583], length 0
Send traffic from terminal 2 on laptop
learner@laptop:~$ ping -c 2 10.77.10.11PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data.
64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.148 ms
64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.072 ms

--- 10.77.10.11 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1012ms
rtt min/avg/max/mdev = 0.072/0.110/0.148/0.038 mslearner@laptop:~$ curl -sS http://10.77.20.80/hello.txtHello from web.learner@laptop:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Terminal 2 repeats the same ping and web request for the host-filtered recording.
Steps (6)
  1. Type ping -c 2 10.77.10.11
  2. Press Enter
  3. Output: PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data. 64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.148 ms 64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.072 ms --- 10.77.10.11 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1012ms rtt min/avg/max/mdev = 0.072/0.110/0.148/0.038 ms
  4. Type curl -sS http://10.77.20.80/hello.txt
  5. Press Enter
  6. Output: Hello from web.

These captures are two runs of the same commands. They are not two views of one run. Times and client port numbers can differ; your number will differ too. Compare which exchanges were retained, not whether every changing number matches.

Check your answer

No. The host filter left the phone ping out of web.pcap. No viewing choice can bring excluded frames back into that file. The ping still ran; the filter limited its recording.

A display filter selects which already-recorded frames are shown. Open all.pcap in Wireshark. In its display-filter field, type ip.addr == 10.77.20.80 and press Enter. The two equals signs mean “equals.” This expression matches either IPv4 address in the packet.

The filtered list in Wireshark 4.2.2 on the course VM, Ubuntu 24.04.4 LTS.
  1. The green bar applies ip.addr == 10.77.20.80.
  2. Frame 9 is the first shown row.
  3. The GET /hello.txt HTTP/1.1 request remains visible.

This screenshot is a separate run. Its status bar reported 24 frames in the file and 12 displayed. The filter hid the frames before 9 without removing them. The replay’s file had 20 frames; counts differ between runs.

Clear that field and apply the empty filter. The other recorded rows can appear again because the file still contains them. Try tcp.port == 80 next: it matches either TCP port. Neither expression is a capture command; both belong in Wireshark’s display-filter field.

What you want Capture filter Display filter
Traffic to or from web’s IPv4 address host 10.77.20.80 ip.addr == 10.77.20.80
TCP traffic using port 80 at either end tcp port 80 tcp.port == 80

For this lab’s IPv4 web exchange, each capture filter matches the same traffic as the display filter beside it. Their spelling differs. An address filter can include several services on that machine; a port filter selects the named port.

“Both kinds use the same words.” host belongs to capture syntax; ip.addr belongs to display syntax. Check where you are entering the expression before changing its values.

“A display filter deletes frames.” Clear it to reveal the retained rows. The loss happens when a capture filter prevents recording in the first place.

For a short lab experiment, record broadly and narrow the display afterwards. A capture filter is useful when the recording would be too large. Keep the capture point and filter in your notes either way.

Capture without a filter while requesting hello.txt, then index.html. Use a display filter to show only the second request. Here http.request.uri names the requested path; compare it with the quoted text "/index.html" using ==.

Solution

Use the same two-terminal pattern, with a different output filename and both curl requests in terminal 2. Stop after both return. Open the file and apply http.request.uri == "/index.html". It selects the request naming that path. Clearing it reveals the first request again. This field selects a request, not every frame of its conversation.

Other protocols bring their own filters when the course teaches them. You do not need a large filter list before you can investigate one exchange.

  • Capture filters decide what evidence is kept.
  • Display filters hide rows without removing their frames.
  • Record broadly when the short experiment allows it.

Next, Following an exchange connects rows into one conversation.