tcpdump#
tcpdump is the operator’s go-to packet capture utility on Linux
and macOS. This page covers basic filters, protocol selection,
boolean composition, and a set of advanced BPF expressions that
target specific TCP / IP fields.
Basic#
Command |
Effect |
|---|---|
|
Match any traffic involving 192.168.1.1 as destination or source. |
|
Match a particular source only. |
|
Match a particular destination only. |
|
Match any traffic involving port 25 as source or destination. |
|
Source port 25. |
|
Destination port 25. |
|
Match network 192.168. |
|
Source network. |
|
Destination network. |
Protocol#
$ tcpdump -i eth1 arp
$ tcpdump -i eth1 ip
$ tcpdump -i eth1 tcp
$ tcpdump -i eth1 udp
$ tcpdump -i eth1 icmp
Boolean#
Negation ! or not, concatenate && or and, alternate
|| or or.
Match TCP traffic on port 80 to 192.168.1.254 or 192.168.1.200.
$ tcpdump -i eth1 '((tcp) and (port 80) and ((dst host 192.168.1.254) or (dst host 192.168.1.200)))'
Match ICMP traffic to a specific MAC.
$ tcpdump -i eth1 '((icmp) and ((ether dst host 00:01:02:03:04:05)))'
Match any traffic to a destination network except a specific host.
$ tcpdump -i eth1 '((tcp) and (dst net 192.168) and (not dst host 192.168.1.200))'
Advanced#
Command |
Effect |
|---|---|
|
Match IP header has options set (binary). |
|
Match IP header has options set (hex). |
|
Match any fragmentation occurring. |
|
Match the fragments and the last fragments. |
|
Match traceroute usage on the network. |
|
Match packets longer than 600 bytes. |
|
Match any TCP traffic with a source port > 1024. |
|
Match packets with only SYN flag set. |
|
Match SYN, ACK (00010010 or 18 in decimal). |
|
Match either SYN only or SYN-ACK datagrams. |
|
Match PSH-ACK packets. |
|
Match any combination containing FIN. |
|
Match RST flag. |
|
Easier way to filter flags. |
|
Match all packages with TCP-SYN or TCP-FIN set. |
|
Match any packet containing the MAIL command from SMTP exchanges. |
|
Match any packets containing GET requests. |
|
SSH connection on any port (look for |
|
Find connections to older OpenSSH (1.99..). |
|
Match ICMP messages type 4 (congestion). |