Skip to content

tcpdump

85 commands

The classic packet capture tool: capture and filter traffic with BPF expressions and write it to pcap files for later analysis.

  • packet capture
  • pcap
  • BPF

Install tcpdump

sudo apt install tcpdump

Interface Selection1

tcpdump -D

Lists all available network interfaces on the system that can be captured.

Basic Capture2

tcpdump -i eth0

Captures all traffic flowing through the specific interface named eth0.

tcpdump -i any

Captures traffic from all active interfaces simultaneously (Pseudo-device capture).

Output Formatting5

tcpdump -n

Disables DNS name resolution to display IP addresses instead of hostnames.

Link
tcpdump -nn

Disables both DNS name resolution and port name resolution (shows port numbers).

Link
tcpdump -t

Disables timestamp printing on each line.

Link
tcpdump -tt

Prints an unformatted unix epoch timestamp on each line.

Link
tcpdump -tttt

Prints a human-readable date and timestamp for every packet.

Link

Capture Count1

tcpdump -c 10

Captures exactly 10 packets and then automatically exits.

Link

Verbosity3

tcpdump -v

Enables verbose output to see TTL, ID, total length, and options.

Link
tcpdump -vv

Enables extra verbose output including NFS and SMB file decoding.

Link
tcpdump -vvv

Enables maximum verbosity for full protocol decoding and analysis.

Link

Quiet Output1

tcpdump -q

Prints less protocol information for a cleaner, easier to read line.

Link

Packet Display3

tcpdump -A

Prints packets in ASCII format, useful for reading web pages or plain text data.

Link
tcpdump -X

Prints packets in both Hex and ASCII format, essential for payload analysis.

Link
tcpdump -xx

Prints the full packet data in hex, including the ethernet header.

Link

Snapshot Length1

tcpdump -s 0

Sets snapshot length to default (unlimited) to capture full packet bodies instead of truncating.

Link

Writing to File1

tcpdump -w capture.pcap

Writes raw packet data to a standard PCAP file for later analysis.

Link

Reading from File1

tcpdump -r capture.pcap

Reads and analyzes packets from a previously saved PCAP file.

Link

File Rotation2

tcpdump -C 100 -w capture.pcap

Rotates the capture file every 100 million bytes (approx 100MB).

Link
tcpdump -G 3600 -w capture_%H.pcap

Rotates the capture file every 3600 seconds (1 hour) incorporating timestamp into filename.

Link

Host Filter1

tcpdump host 192.168.1.50

Filters traffic specifically to or from the host IP 192.168.1.50.

Link

Direction Filter2

tcpdump src 192.168.1.50

Captures only traffic originating from the specific IP address.

Link
tcpdump dst 192.168.1.50

Captures only traffic destined to the specific IP address.

Link

Network Filter1

tcpdump net 10.0.0.0/24

Captures all traffic belonging to the 10.0.0.0/24 subnet.

Link

Port Filter1

tcpdump port 80

Captures traffic flowing through port 80 (HTTP) regardless of direction.

Link

Port Range1

tcpdump portrange 1000-2000

Captures traffic on a range of ports from 1000 to 2000.

Link

Protocol Filter5

tcpdump tcp

Filters output to show only TCP protocol traffic.

Link
tcpdump udp

Filters output to show only UDP protocol traffic.

Link
tcpdump icmp

Filters output to show only ICMP (Ping/Unreachable) traffic.

Link
tcpdump arp

Filters output to show only ARP address resolution traffic.

Link
tcpdump ip6

Filters output to show only IPv6 traffic.

Link

Logical Operators3

tcpdump "src 10.0.0.1 and dst port 80"

Combines filters to match packets from 10.0.0.1 going to port 80.

Link
tcpdump "port 80 or port 443"

Matches packets using either port 80 or port 443.

Link
tcpdump "not port 22"

Excludes all SSH traffic from the capture.

Link

Complex Logic1

tcpdump "host 10.0.0.1 and (port 80 or port 443)"

Uses parentheses to group logic for a specific host on web ports.

Link

TCP Flags5

tcpdump "tcp[tcpflags] & tcp-syn != 0"

Captures only TCP packets with the SYN flag set (connection requests).

Link
tcpdump "tcp[tcpflags] & tcp-ack != 0"

Captures only TCP packets with the ACK flag set.

Link
tcpdump "tcp[tcpflags] & tcp-fin != 0"

Captures only TCP packets with the FIN flag set (connection termination).

Link
tcpdump "tcp[tcpflags] & tcp-rst != 0"

Captures only TCP packets with the RST flag set (connection reset).

Link
tcpdump "tcp[tcpflags] & tcp-push != 0"

Captures packets with the PUSH flag, indicating data should be processed immediately.

Link

Specific Flows1

tcpdump "tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)"

Captures only SYN-ACK packets, representing the server response in a handshake.

Link

Packet Size2

tcpdump "less 32"

Captures packets smaller than 32 bytes.

Link
tcpdump "greater 1000"

Captures packets larger than 1000 bytes.

Link

Advanced BPF3

tcpdump "ip[2:2] > 600"

Uses byte offset filtering to capture packets with a total IP length greater than 600.

Link
tcpdump "tcp[13] & 2 != 0"

Manual BPF filter checking the 13th byte of TCP header for the SYN flag.

Link
tcpdump "ip[6] & 128 != 0"

Detects packets with the 'Evil Bit' (Reserved bit) set in the IP header.

Link

ICMP Type2

tcpdump "icmp[icmptype] == icmp-echo"

Captures only ICMP Echo Requests (standard Pings).

Link
tcpdump "icmp[icmptype] == icmp-echoreply"

Captures only ICMP Echo Replies (Pong).

Link

Broadcast/Multicast2

tcpdump "ether dst ff:ff:ff:ff:ff:ff"

Captures layer 2 broadcast traffic specifically.

Link
tcpdump "ip multicast"

Captures traffic destined for multicast groups.

Link

VLAN Capture2

tcpdump vlan

Filters for traffic containing 802.1Q VLAN headers.

Link
tcpdump vlan 100

Captures traffic specifically tagged with VLAN ID 100.

Link

IPv6 Capture1

tcpdump ip6 proto 6

Captures IPv6 traffic specifically using the TCP protocol (Protocol 6).

Link

Security Forensics7

tcpdump -X -s 0 port 80

Captures full HTTP packets in Hex/ASCII to inspect payloads for malicious data.

Link
tcpdump "tcp[tcpflags] == 0"

Detects Null Scan attacks where a packet is sent with no TCP flags set.

Link
tcpdump "tcp[tcpflags] & (tcp-fin|tcp-urg|tcp-push) == (tcp-fin|tcp-urg|tcp-push)"

Detects Xmas Tree scans which set the FIN, URG, and PUSH flags simultaneously.

Link
tcpdump "tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420"

Advanced filter matching the bytes 'GET ' at the beginning of the TCP payload.

Link
tcpdump "tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354"

Advanced filter matching the bytes 'POST' at the beginning of the TCP payload.

Link
tcpdump "tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x48545450"

Matches 'HTTP' in payload, useful for finding HTTP responses or custom headers.

Link
tcpdump -l

Makes stdout line-buffered, allowing immediate piping to tools like grep.

Link

Tunnel Traffic2

tcpdump proto 47

Captures GRE (Generic Routing Encapsulation) tunnel traffic.

Link
tcpdump port 4789

Captures VXLAN traffic commonly used in modern cloud and container networking.

Link

Performance Tuning2

tcpdump -B 4096

Increases the capture buffer size to 4096KB to prevent packet drops during heavy load.

Link
tcpdump -K

Don't verify checksums (default on some systems), improves performance on high-speed interfaces.

Link

User Agent Detection1

tcpdump -A -s 0 "tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)"

Filters for TCP segments that actually contain data (payload) to ignore empty ACKs.

Link

DNS Analysis1

tcpdump udp port 53

Standard filter for monitoring DNS queries and responses.

Link

NTP Analysis1

tcpdump udp port 123

Captures Network Time Protocol traffic for troubleshooting sync issues.

Link

DHCP Analysis1

tcpdump port 67 or port 68

Captures DHCP discovery, offer, request, and ack sequences.

Link

Intrusion Detection2

tcpdump "icmp[icmptype] == icmp-timexceed"

Captures TTL Exceeded messages, useful for visualizing traceroutes targeting your network.

Link
tcpdump "icmp[icmptype] == icmp-unreach"

Captures Destination Unreachable messages, often indicating closed ports or firewall rejects.

Link

Red Team1

tcpdump -w sensitive.pcap port 21 or port 23 or port 110

Captures cleartext protocols (FTP, Telnet, POP3) to harvest credentials.

Link

Advanced Filtering1

tcpdump -i eth0 -n "broadcast or multicast"

Identifies noisy broadcast traffic that might be causing network storms.

Link

Specific Host Noise1

tcpdump -n "not host 192.168.1.50"

Captures everything EXCEPT traffic from a specific noisy backup server or admin host.

Link

Packet Header Analysis1

tcpdump -x

Prints payload in hex without ASCII, useful for strict byte-level header verification.

Link

Absolute Sequence1

tcpdump -S

Prints absolute TCP sequence numbers instead of relative ones, critical for TCP stream analysis.

Link

MPLS Capture1

tcpdump mpls

Captures Multi-Protocol Label Switching packets.

Link

Directional Interface2

tcpdump -Q in

Captures only ingress (incoming) traffic on the interface (Linux specific).

Link
tcpdump -Q out

Captures only egress (outgoing) traffic on the interface (Linux specific).

Link

Raw Capture1

tcpdump -U -w capture.pcap

Writes packets to file immediately as they arrive without buffering (Packet Buffered).

Link

Protocol Specific2

tcpdump proto 89

Captures OSPF routing protocol traffic.

Link
tcpdump port 179

Captures BGP (Border Gateway Protocol) traffic.

Link

Complex Exclusion1

tcpdump "host 10.0.0.1 and not port 22 and not port 53"

Focuses on a host while removing standard administrative noise like SSH and DNS.

Link