tcpdump BPF Filter Reference

tcpdump BPF filter expressions — host, port, proto, flags — with combination logic.

Build and look up tcpdump/BPF capture filter expressions — host, net, port, protocol and TCP flag primitives — combined with and/or/not, with a live filter builder. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is a BPF capture filter?

A Berkeley Packet Filter is a low-level expression the kernel uses to decide which packets to hand to tcpdump. Filters combine primitives like host, port and proto with the boolean operators and, or and not, evaluated per packet.

Build tcpdump BPF filters without guessing the syntax

tcpdump uses Berkeley Packet Filter expressions to capture only the traffic you care about. This tool lets you assemble a filter from host, network, port, protocol, direction, and TCP-flag primitives — joining them with and/or/not — and includes a reference of the common primitives. It runs entirely in your browser.

How it works

A BPF filter is a boolean expression evaluated per-packet in the kernel before data reaches userspace. Common primitives are host, net, port, portrange, protocol names (tcp, udp, icmp), and direction qualifiers src/dst. Combine them with and, or, and not, using parentheses (quoted in the shell) for grouping:

tcpdump -i eth0 "tcp and host 10.0.0.5 and port 443"
tcpdump -i any "udp port 53 or icmp"
tcpdump -i eth0 "tcp[tcpflags] & tcp-syn != 0 and not net 10.0.0.0/8"

Primitive reference

PrimitiveMeaning
host 10.0.0.5Matches either src or dst is this address
src host 10.0.0.5Matches only when source is this address
dst host 10.0.0.5Matches only when destination is this address
net 10.0.0.0/24Matches any address in the subnet
port 443Either src or dst port is 443
src port 1024Source port is 1024
portrange 8000-8100Either port falls in the inclusive range
tcp / udp / icmpMatch by protocol
tcp[tcpflags] & tcp-syn != 0Any packet with the SYN bit set

TCP flag filters

TCP flag matching uses the tcp[tcpflags] byte accessor. Useful patterns:

# Any packet with SYN set (includes SYN-ACK):
tcp[tcpflags] & tcp-syn != 0

# Bare SYN only (connection initiation, no ACK):
tcp[tcpflags] == tcp-syn

# RST (connection resets — useful for spotting refused connections):
tcp[tcpflags] & tcp-rst != 0

# FIN (connection teardown):
tcp[tcpflags] & tcp-fin != 0

Practical filter cookbook

Watch all traffic to/from a single host:

tcpdump -i eth0 "host 192.168.1.10"

Capture only HTTPS and DNS:

tcpdump -i any "tcp port 443 or udp port 53"

Find connection attempts to a server (bare SYNs):

tcpdump -i eth0 "tcp[tcpflags] == tcp-syn and dst host 10.0.0.5"

Exclude internal subnet, capture everything else:

tcpdump -i eth0 "not net 10.0.0.0/8"

Write to file for analysis in Wireshark:

tcpdump -i eth0 -w capture.pcap "tcp port 5432"

Shell and performance tips

  • Always quote the filter expression with double quotes so the shell does not expand &, <, >, or parentheses.
  • Use -n to disable DNS reverse lookup and -nn to also suppress port-to-name translation — both keep capture overhead low and output literal.
  • BPF filters run in the kernel and drop non-matching packets before they reach tcpdump. Wireshark display filters operate differently — they hide already-captured packets but do not reduce kernel-level load during a live capture.
  • Limit capture size with -s snaplen (for example -s 128) when you only need headers and want to reduce disk and memory use.