LinuxCommandLibrary

tcpdump

TLDR

Capture packets on default interface

$ tcpdump
copy
Capture on specific interface
$ tcpdump -i [eth0]
copy
Capture only packets to/from host
$ tcpdump host [192.168.1.1]
copy
Capture packets on specific port
$ tcpdump port [80]
copy
Capture and save to file
$ tcpdump -w [capture.pcap]
copy
Read packets from file
$ tcpdump -r [capture.pcap]
copy
Capture with verbose output
$ tcpdump -v
copy
Capture HTTP traffic
$ tcpdump -A port [80]
copy
Capture packets with specific protocol
$ tcpdump icmp
copy
Capture limited number of packets
$ tcpdump -c [100]
copy
Don't resolve hostnames
$ tcpdump -n
copy

SYNOPSIS

tcpdump [options] [filter expression]

DESCRIPTION

tcpdump is a packet analyzer that captures and displays network traffic. It uses libpcap to capture packets from network interfaces and can filter traffic using Berkeley Packet Filter (BPF) syntax.
The tool can capture packets in real-time, display their contents in various formats, and save them to files for later analysis. Output can show packet headers, full content, or hexadecimal dumps.
tcpdump is essential for network troubleshooting, security analysis, and protocol debugging. It's the command-line counterpart to graphical tools like Wireshark.

PARAMETERS

-i interface

Capture on specific interface.
-w file
Write packets to file.
-r file
Read packets from file.
-c count
Capture only count packets.
-n
Don't resolve hostnames.
-nn
Don't resolve hostnames or ports.
-v, -vv, -vvv
Verbose output levels.
-A
Print packets in ASCII.
-X
Print packets in hex and ASCII.
-s snaplen
Capture snaplen bytes per packet (0=full).
-e
Print link-layer header.
-q
Quick output (less protocol info).
-D
List available interfaces.

FILTER EXPRESSIONS

host ip: Filter by host
port num: Filter by port
src/dst: Source or destination
tcp/udp/icmp: Protocol types
and/or/not: Boolean operators
Example: `tcpdump 'tcp port 80 and host 192.168.1.1'`

CAVEATS

Requires root privileges. Packet capture can impact performance on high-traffic networks. Full packet capture uses significant disk space. Some protocols are encrypted and contents cannot be viewed.

HISTORY

tcpdump was originally written by Van Jacobson, Craig Leres, and Steven McCanne at the Lawrence Berkeley National Laboratory in 1988. It became the foundation for network packet analysis on Unix systems. The libpcap library was extracted from tcpdump and is now used by many network analysis tools including Wireshark.

SEE ALSO

wireshark(1), tshark(1), ngrep(1), pcap(3)

Copied to clipboard