Console9

tcpdump flags and BPF filter reference

Complete reference for tcpdump flags, output formats, and Berkeley Packet Filter expression syntax.

tcpdump flags and BPF filter reference

Complete reference for tcpdump flags, output formats, and Berkeley Packet Filter expression syntax.

tcpdump Command Flags

FlagDescriptionExample
-i IFACECapture on a specific interface. Use any for all.tcpdump -i eth0
-DList available interfaces for capture.tcpdump -D
-c NStop after capturing N packets.tcpdump -c 100
-w FILEWrite raw packets to a pcap file.tcpdump -w capture.pcap
-r FILERead packets from a pcap file.tcpdump -r capture.pcap
-nDo not resolve hostnames.tcpdump -n
-nnDo not resolve hostnames or port names.tcpdump -nn
-v/ -vv/ -vvvIncrease verbosity level.tcpdump -vv
-APrint packet contents in ASCII.tcpdump -A port 80
-XPrint packet contents in hex and ASCII.tcpdump -X
-s NCapture N bytes per packet (0 = full packet).tcpdump -s 0
-G SECSRotate capture files every N seconds.tcpdump -G 3600 -w file_%H.pcap
-C MBRotate capture files every N megabytes.tcpdump -C 100
-W NKeep only N rotation files.tcpdump -W 10
-qQuiet output — print less protocol information.tcpdump -q
-ePrint link-layer (MAC) headers.tcpdump -e

BPF Filter Expressions

FilterDescriptionExample
host IPMatch traffic to/from a specific host.tcpdump host 203.0.113.1
src IPMatch traffic from a source IP.tcpdump src 10.0.0.1
dst IPMatch traffic to a destination IP.tcpdump dst 10.0.0.2
port NMatch traffic on a specific port (src or dst).tcpdump port 443
src port NMatch traffic from a source port.tcpdump src port 22
dst port NMatch traffic to a destination port.tcpdump dst port 80
tcpMatch TCP packets only.tcpdump tcp
udpMatch UDP packets only.tcpdump udp
icmpMatch ICMP packets only.tcpdump icmp
net CIDRMatch traffic to/from a subnet.tcpdump net 10.0.0.0/24
andCombine filters with logical AND.tcpdump host 10.0.0.1 and port 22
orCombine filters with logical OR.tcpdump port 80 or port 443
notNegate a filter.tcpdump not port 22
portrange N-MMatch a range of ports.tcpdump portrange 8000-9000

TCP Flag Filters

FilterDescriptionExample
tcp[tcpflags] & tcp-syn != 0Match SYN packets (connection initiation).tcpdump 'tcp[tcpflags] & tcp-syn != 0'
tcp[tcpflags] & tcp-rst != 0Match RST packets (connection reset).tcpdump 'tcp[tcpflags] & tcp-rst != 0'
tcp[tcpflags] & tcp-fin != 0Match FIN packets (connection close).tcpdump 'tcp[tcpflags] & tcp-fin != 0'