
tcpdump is the world's premier network analysis tool—combining both power and simplicity into a single command-line interface. This guide will show you how to use it.
tcpdump is a powerful command-line packet analyzer. It allows you to capture and inspect network traffic in real-time. This tool is invaluable for network administrators, security professionals, and anyone who needs to understand network behavior.
In this tutorial, we'll explore 150 practical examples of using tcpdump. These examples will cover a wide range of use cases, from basic traffic capture to advanced filtering and analysis.
The basic syntax of tcpdump is:
tcpdump [options] [expression]options: Modify the behavior of tcpdump, such as specifying the interface to capture on or the output format.expression: Defines what kind of traffic to capture. This is where you specify hostnames, IP addresses, ports, protocols, and other criteria.To capture all traffic on a specific interface, use the -i flag followed by the interface name. For example, to capture traffic on the eth0 interface:
tcpdump -i eth0To see a list of all available interfaces, use the command:
tcpdump -DTo capture traffic to or from a specific host, use the host keyword followed by the hostname or IP address:
tcpdump host 192.168.1.100This will capture all traffic to and from the host with the IP address 192.168.1.100.
To capture traffic on a specific port, use the port keyword followed by the port number:
tcpdump port 80This will capture all traffic on port 80 (HTTP).
You can combine filters using and, or, and not operators. For example, to capture all traffic to or from host 192.168.1.100 on port 80, use:
tcpdump host 192.168.1.100 and port 80To capture traffic from 192.168.1.100 on either port 80 or 443, use:
tcpdump src host 192.168.1.100 and \( port 80 or port 443 \)To filter by protocol, use the ip, tcp, udp, or other protocol keywords. For example, to capture only TCP traffic:
tcpdump tcpTo capture only UDP traffic:
tcpdump udpTo filter by source or destination host or port, use the src or dst keywords:
tcpdump src host 192.168.1.100This will capture all traffic from the host 192.168.1.100.
tcpdump dst port 443This will capture all traffic destined for port 443.
To capture traffic within a specific network, use the net keyword:
tcpdump net 192.168.1.0/24This will capture all traffic within the 192.168.1.0/24 network.
To save captured traffic to a file, use the -w flag followed by the filename:
tcpdump -w capture.pcap -i eth0This will save all captured traffic on the eth0 interface to the file capture.pcap.
You can later analyze this file using tcpdump or another packet analyzer like Wireshark.
To read captured traffic from a file, use the -r flag followed by the filename:
tcpdump -r capture.pcapThis will read and display the traffic from the file capture.pcap.
You can control the verbosity of tcpdump output using the -v, -vv, or -vvv flags.
-v: Verbose output.-vv: More verbose output.-vvv: Most verbose output.For example:
tcpdump -vv -i eth0Here are 150 tcpdump examples to help you isolate traffic in various situations:
eth0:tcpdump -i eth0wlan0:tcpdump -i wlan0tcpdump -i anytcpdump -c 100tcpdump -Dtcpdump -n -i eth0tcpdump -nn -i eth0tcpdump -A -i eth0tcpdump -X -i eth0tcpdump -tttt -i eth0tcpdump -v -i eth0tcpdump -vvv -i eth0tcpdump -s 0 -i eth0tcpdump -l -i eth0 | tee capture.txttcpdump host 192.168.1.100tcpdump host example.comtcpdump src host 192.168.1.100tcpdump dst host 192.168.1.100tcpdump host 192.168.1.100 and host 192.168.1.200tcpdump port 80tcpdump port 443tcpdump port 22tcpdump port 53tcpdump port 25tcpdump port 21tcpdump src port 80tcpdump dst port 443tcpdump portrange 8000-9000tcpdump tcptcpdump udptcpdump icmptcpdump arptcpdump ip6tcpdump net 192.168.1.0/24tcpdump src net 192.168.1.0/24tcpdump dst net 192.168.1.0/24tcpdump dst host 192.168.1.100 and dst port 80tcpdump src host 192.168.1.100 and src port 443tcpdump host 192.168.1.100 and \( port 80 or port 443 \)tcpdump not icmptcpdump not port 22tcpdump -i eth0 not \( src host 192.168.1.50 and dst port 22 \)tcpdump port 80 or port 443tcpdump not port 80 and not port 443tcpdump 'tcp[tcpflags] & tcp-syn != 0'tcpdump 'tcp[tcpflags] & tcp-ack != 0'tcpdump 'tcp[tcpflags] & tcp-rst != 0'tcpdump 'tcp[tcpflags] & tcp-fin != 0'tcpdump 'tcp[tcpflags] & tcp-urg != 0'tcpdump 'tcp[tcpflags] & tcp-push != 0'tcpdump 'tcp[tcpflags] = tcp-syn'tcpdump 'tcp[tcpflags] = 0x12'tcpdump 'tcp[tcpflags] = 0x14'tcpdump 'tcp[tcpflags] = 0x11'tcpdump 'tcp[tcpflags] = 0x18'tcpdump 'tcp[tcpflags] = 0x00'tcpdump 'tcp[tcpflags] & 0x29 = 0x29'tcpdump -w capture.pcap -i eth0tcpdump -r capture.pcaptcpdump -r capture.pcap tcp port 80tcpdump -w capture.pcap -C 100 -i eth0tcpdump -w capture-%Y%m%d%H%M%S.pcap -G 3600 -i eth0tcpdump -w capture.pcap -C 100 -W 10 -i eth0tcpdump 'ip[6:2] & 0x1fff != 0'tcpdump 'ip[8] = 128'tcpdump 'ip[8] = 64'tcpdump 'ip[1] & 0xfc = 0xb8'tcpdump 'ip[1] & 0x03 = 3'tcpdump greater 500tcpdump less 100tcpdump -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'tcpdump -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354'tcpdump -n 'udp dst port 53'tcpdump -n 'udp port 67 or udp port 68'tcpdump 'tcp port 443 and tcp[((tcp[12:1] & 0xf0) >> 2)] = 0x16 and tcp[((tcp[12:1] & 0xf0) >> 2)+5] = 0x01'tcpdump -nn -A -i eth0 'port 21'tcpdump -nn -A -s 0 -i eth0 'tcp dst port 80'tcpdump -nn -A -i eth0 'tcp port 25 or tcp port 587'tcpdump -nn -A -i eth0 'tcp port 110 or tcp port 143'tcpdump -nn -e -i eth0 'arp[6:2] = 2'tcpdump -nn -i eth0 'udp port 53 and greater 512'tcpdump -nn -i eth0 'udp src port 53 and greater 300'tcpdump -nn -e -i eth0 'udp src port 67'tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn and (dst port 22 or dst port 3389 or dst port 445)'tcpdump -nn -tttt -i eth0 'tcp dst port 22 and tcp[tcpflags] = tcp-syn' -c 200tcpdump -nn -A -i eth0 'tcp port 389 or tcp port 636'tcpdump -nn -i eth0 'tcp port 88 or udp port 88'tcpdump -nn -A -i eth0 'tcp port 23'tcpdump -nn -s 0 -w tls-handshakes.pcap -i eth0 'tcp port 443 and (tcp[((tcp[12:1] & 0xf0) >> 2)] = 0x16)'tcpdump -nn -e -i eth0 'vlan'tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn and dst portrange 1-1023 and not (dst port 80 or dst port 443 or dst port 22 or dst port 53 or dst port 25)'tcpdump -nn -i eth0 'udp dst port 53 and not dst host 10.0.0.1'tcpdump -nn -i eth0 'tcp dst port 445 and src net 10.0.0.0/8 and dst net 10.0.0.0/8'tcpdump -nn -i eth0 'tcp dst port 5985 or tcp dst port 5986'tcpdump -nn -i eth0 'tcp dst port 3389 and src net 192.168.0.0/16 and dst net 192.168.0.0/16'tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn and (dst port 4444 or dst port 1234 or dst port 5555 or dst port 9001)'tcpdump -nn -tttt -i eth0 'tcp dst port 443 and tcp[tcpflags] = tcp-syn' -c 500tcpdump -nn -i eth0 'icmp and greater 100'tcpdump -nn -i eth0 'tcp dst port 443 and (dst host 1.1.1.1 or dst host 8.8.8.8 or dst host 8.8.4.4 or dst host 9.9.9.9)'tcpdump -nn -i eth0 'udp port 1194 or tcp port 1194'tcpdump -nn -i eth0 'udp port 51820'tcpdump -nn -i eth0 'tcp dst port 3333 or tcp dst port 8333 or tcp dst port 9999'tcpdump -nn -s 0 -w ntlm-traffic.pcap -i eth0 'tcp port 445 or tcp port 139'tcpdump -nn -i eth0 'src net 10.0.0.0/8 and not dst net 10.0.0.0/8 and greater 1000'tcpdump -nn -i eth0 'tcp dst port 1080'tcpdump -nn -i eth0 'icmp[0] = 8' -c 500tcpdump -nn -tttt -i eth0 'tcp dst port 443 and tcp[tcpflags] = tcp-syn and dst host 192.0.2.100'tcpdump -nn -i eth0 'tcp dst port 389' -c 1000tcpdump -nn -A -s 0 -i eth0 'tcp dst port 5985'tcpdump -nn -i eth0 'udp port 53' -c 5000 -w dns-baseline.pcaptcpdump -nn -A -s 0 -i eth0 'tcp dst port 80 and src host 10.0.1.50'tcpdump -nn -X -i eth0 'icmp[0] = 8 and greater 64'tcpdump -nn -tttt -i eth0 'tcp[tcpflags] = tcp-syn and dst host 10.0.1.100'tcpdump -nn -v -i eth0 'udp src port 53' -c 200tcpdump -nn -i eth0 'udp dst port 53 and src host 10.0.1.50' -c 1000tcpdump -nn -s 0 -w evidence-$(date +%Y%m%d-%H%M%S).pcap -i eth0 'host 10.0.1.50'tcpdump -nn -s 0 -G 300 -w incident-%Y%m%d-%H%M%S.pcap -i eth0 'host 10.0.1.50'tcpdump -nn -s 0 -c 10000 -w triage.pcap -i eth0 'host 10.0.1.50'tcpdump -nn -s 0 -A -i eth0 'tcp src port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'tcpdump -nn -i eth0 'udp dst port 53' -l | tee dns-queries.logtcpdump -nn -s 0 -w malicious.pcap -i eth0 'host 203.0.113.10 or host 198.51.100.20 or host 192.0.2.30'tcpdump -nn -tttt -i eth0 'tcp[tcpflags] = tcp-syn'tcpdump -nn -s 0 -C 100 -W 50 -w evidence.pcap -i eth0 'host 10.0.1.50'tcpdump -nn -v -i eth0 'icmp[0] = 3 or icmp[0] = 11'tcpdump -nn -A -s 0 -i eth0 'tcp dst port 25 or tcp dst port 587 or tcp dst port 465'tcpdump -nn -s 0 -w subnet-capture.pcap -i eth0 'net 10.0.1.0/24'tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn and src host 10.0.1.50 and dst net 10.0.0.0/8'tcpdump -nn -i eth0 'src host 10.0.1.50 and dst net 10.0.0.0/8 and greater 1000'timeout 3600 tcpdump -nn -s 0 -w legal-hold-$(date +%Y%m%d).pcap -i eth0 'host 10.0.1.50'tcpdump -nn -i eth0 'src net 10.0.0.0/8 and not dst net 10.0.0.0/8 and not (dst port 80 or dst port 443 or dst port 53)'tcpdump -nn -i eth0 'tcp[14:2] = 0 and tcp[tcpflags] & tcp-ack != 0'tcpdump -nn -v -i eth0 'icmp[0] = 3 and icmp[1] = 4'tcpdump -nn -i eth0 'ip[6] & 0x40 != 0'tcpdump -nn -i eth0 'tcp port 179'tcpdump -nn -i eth0 'udp port 123'tcpdump -nn -e -vv -i eth0 'udp port 67 or udp port 68'tcpdump -nn -i eth0 'ip proto 112'tcpdump -nn -i eth0 'udp dst port 1985'tcpdump -nn -i eth0 'udp port 162'tcpdump -nn -e -i eth0 'arp'tcpdump -nn -v -i eth0 'udp port 53'tcpdump -nn -A -s 0 -i eth0 'tcp port 5060 or udp port 5060'tcpdump -nn -i eth0 'udp portrange 16384-32767'tcpdump -nn -i eth0 'udp port 1812 or udp port 1813'tcpdump -nn -i eth0 'tcp port 49'tcpdump -nn -i eth0 'ip proto 47'tcpdump -nn -i eth0 'ip proto 89'tcpdump -nn -i eth0 'ip proto 88'tcpdump -nn -i eth0 'dst net 224.0.0.0/4'tcpdump -nn -v -i eth0 'ip[1] & 0xfc != 0'These examples should provide a solid foundation for using tcpdump to analyze network traffic.
Happy hunting!
-Daniel