Capture Filters
Capture filters are applied before Wireshark records packets. They use the Berkeley Packet Filter (BPF) syntax and are much faster than display filters because they drop packets at the kernel level.
Capture vs Display Filters
Where to Set Capture Filters
Before starting a capture, enter your filter in the Capture Filter field at the top of the main window, next to the interface list. You can also set them via the command line.
Basic Syntax
BPF expressions consist of one or more primitives. Primitives usually consist of an identifier (name or number) preceded by one or more qualifiers.
1[qualifier] [identifier]
Common Qualifiers
| Qualifier | Description |
|---|---|
| host | IP or hostname |
| net | Network with optional mask (e.g., /24) |
| port | TCP or UDP port number |
| portrange | Range of ports |
| src | Source qualifier (can prefix host/port) |
| dst | Destination qualifier (can prefix host/port) |
| ether | Ethernet (MAC) address |
| proto | Protocol (ip, ip6, arp, rarp, tcp, udp, icmp) |
Host & Port Filters
host 192.168.1.1
Traffic to or from host 192.168.1.1
net 192.168.1.0/24
Traffic to or from the 192.168.1.0/24 subnet
port 80
Traffic on port 80 (HTTP)
portrange 1000-2000
Traffic on ports 1000 through 2000
src host 10.0.0.1
Traffic originating from 10.0.0.1
dst host 10.0.0.1
Traffic destined for 10.0.0.1
src port 53
Traffic from source port 53
dst port 443
Traffic to destination port 443
Protocol Filters
tcp
Only TCP traffic
udp
Only UDP traffic
icmp
Only ICMP (ping) traffic
arp
Only ARP traffic
ip6
Only IPv6 traffic
not arp
Exclude ARP traffic
tcp or udp
TCP or UDP traffic
not tcp port 80
All traffic except TCP port 80
Advanced BPF Expressions
You can combine primitives with logical operators: and, or, not, and () for grouping. You can also inspect raw packet bytes.
tcp[13] & 2 != 0
TCP SYN packets only
tcp[13] & 16 != 0
TCP ACK packets only
icmp[icmptype] == icmp-echo
ICMP echo request (ping)
ether host 00:11:22:33:44:55
Traffic to/from MAC address
len > 100
Packets larger than 100 bytes
ip[2:2] > 576
IP packets with total length > 576
TCP Flags Cheat Sheet
tcp[13] & 18 != 0 matches SYN-ACK packets.Common Real-World Examples
1# Capture only HTTP traffic from a specific host tcp port 80 and host 192.168.1.50 # Capture DNS queries (UDP port 53) excluding a server udp port 53 and not host 8.8.8.8 # Capture SSH traffic to or from any host port 22 # Capture all traffic except your own machine not host $(hostname -I | awk '{print $1}') # Capture ICMP echo requests only icmp[icmptype] == icmp-echo # Capture all non-ARP traffic on a subnet not arp and net 10.0.0.0/8 # Capture TCP traffic with the SYN flag set tcp[13] & 2 != 0 # Capture traffic on multiple specific ports port 80 or port 443 or port 22
Using with tshark / dumpcap
Capture filters work identically in command-line tools:
1# tshark with capture filter2tshark -f "port 80" -i eth034# dumpcap with capture filter5dumpcap -f "host 192.168.1.1" -i eth0 -w capture.pcap67# tcpdump (uses same BPF syntax)8tcpdump -i eth0 "tcp port 443 and host 10.0.0.5"
Important Limitation