tcpdump filters for everyday diagnostics
Examples for host, port, VLAN and connection filters.
On a server, tcpdump can capture traffic in place before you open it in a graphical analyzer. Start with one interface and narrow the capture to the traffic you want to inspect.
Capture options
tcpdump -ni eth0 # capture on one interface without name resolution
tcpdump -ni any -c 100 # capture 100 packets across interfaces
tcpdump -ni eth0 -w cap.pcap # write a Wireshark-readable capture file
tcpdump -nnvr cap.pcap # read the file with verbose output
Filter examples
host 10.0.0.5 and port 53 # DNS traffic for a specific host
net 192.168.10.0/24 and not port 22 # subnet traffic excluding SSH
'tcp[tcpflags] & (tcp-syn|tcp-rst) != 0' # match packets with SYN or RST set
'icmp[icmptype] == 3' # destination unreachable
vlan 110 and host 172.16.110.1 # match traffic in the tagged VLAN
'ip[6:2] & 0x1fff != 0' # IPv4 fragments
ether host aa:bb:cc:dd:ee:ff # filter by MAC address
arp or icmp # check for Layer 2 or Layer 3 responses
Longer captures and VLANs
-s 96limits the number of bytes written per packet when you mainly need headers.-G 300 -w 'cap-%H%M.pcap'starts a new capture file every five minutes.- If a VLAN filter returns nothing, the driver may have stripped the tag before capture. Try capturing on the parent interface and check its VLAN offload settings.