tcpdump Packet capture
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
sudo tcpdump -Dsudo tcpdump -i <iface> -nn
sudo tcpdump -i any port 53
sudo tcpdump host <ip>
sudo tcpdump -c 20
sudo tcpdump -Asudo tcpdump -w <file>.pcap
tcpdump -r <file>.pcap
Concepts
- Interface -i, -Q
- BPF filter expression
- Capture kernel buffer
- Output terminal or pcap
Capture
tcpdump -Dtcpdump -i <iface>
tcpdump -i anytcpdump -c <n>
tcpdump -s 0tcpdump -s <bytes>
tcpdump -Q intcpdump -ptcpdump -B <kib>
tcpdump --immediate-mode
tcpdump -IOutput
tcpdump -ntcpdump -nntcpdump -vtcpdump -qtcpdump -Atcpdump -Xtcpdump -xxtcpdump -etcpdump -tttttcpdump -ttttcpdump -ttcpdump -Stcpdump -#tcpdump -ltcpdump --lengths
Save and read
tcpdump -w <file>.pcap
tcpdump -r <file>.pcap
tcpdump -w <file>.pcap --print
tcpdump -U -w <file>.pcap
tcpdump -C <size> -w <file>
tcpdump -W <n>
tcpdump -G <sec> -w <file>-%FT%T.pcap
tcpdump -z gziptcpdump -Z <user>
tcpdump --count -r <file>
tcpdump -F <file>
tcpdump -w - | <cmd>
Filters: hosts and ports
host <ip>src host <ip>
dst host <ip>
net <cidr>
port <n>src port <n>
dst port <n>
portrange <a>-<b>
ether host <mac>
vlan <id>gateway <host>
Filters: protocols and logic
tcpicmpudparpip6ip proto <name|n>
A and BA or Bnot A'(A or B) and C'
less <n>greater <n>
ether broadcastip multicastTCP details
'tcp[tcpflags] & tcp-syn != 0'
'tcp[tcpflags] & tcp-rst != 0'
'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0'
'tcp[tcpflags] == tcp-syn'
'tcp[13] == 2'
'tcp[tcpflags] & tcp-push != 0'
| Flags | Meaning |
|---|---|
[S] |
SYN, connection start |
[S.] |
SYN-ACK |
[.] |
ACK only |
[P.] |
data pushed |
[F.] |
FIN, closing |
[R] |
RST, refused or reset |
Signals and debug
tcpdump -d <filter>
tcpdump -Ktcpdump --version
tcpdump -T <type>
kill -USR1 <pid>
tcpdump --print-sampling=<n>
Recipes
sudo tcpdump -i any -nn port 53
sudo tcpdump -i <iface> -nn -A -s 0 'tcp dst port 80'
sudo tcpdump -i <iface> -nn -w cap -C 100 -W 10 -Z $USER# keeps ten files of about 100 MB each
sudo tcpdump -nn 'dst host <ip> and tcp[tcpflags] == tcp-syn'# add -w syn.pcap to save it for Wireshark
sudo tcpdump -i <iface> -nn -tttt icmp and host <ip>



