Skip to content

TCPDump

tcpdump is a command-line packet analyzer for capturing and inspecting live network traffic. Essential for network troubleshooting and security work.

Source

TCP/IP header diagram

Basic syntax

bash
tcpdump [options] [expression]
  • options — interface, verbosity, output format, write to file
  • expression — filter by host, port, protocol, flags, etc.

Common captures

bash
# List interfaces
tcpdump -D

# All traffic on an interface
tcpdump -i eth0

# Host filter
tcpdump host 192.168.1.100

# Port filter
tcpdump port 80

# Combine filters
tcpdump host 192.168.1.100 and port 80
tcpdump src host 192.168.1.100 and \( port 80 or port 443 \)

# Protocol only
tcpdump tcp
tcpdump udp

Useful options

FlagPurpose
-i eth0Select interface (any for all)
-n / -nnNo DNS / no port-name resolution
-c 100Stop after N packets
-v / -vv / -vvvMore verbose output
-s 0Full packet snap length
-w file.pcapWrite capture to file
-r file.pcapRead capture from file
-X / -XXHex (+ ASCII) dump; -XX includes Ethernet header
-ttttHuman-readable timestamps

TCP flag filters

bash
# SYN packets
tcpdump 'tcp[13] & 2 != 0'

# SYN or ACK
tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-ack) != 0'

Everyday combo

bash
tcpdump -i eth0 -nnvvS -c 50 'tcp port 443'

Press Ctrl+C to stop a live capture.

Curated technical notes — open source on GitHub