Packet capture reference

Packet Capture Command Cookbook

Browse practical tcpdump, tshark, dumpcap, and udpdump commands for common network troubleshooting scenarios.

Commands
18
Tools
4
Mode
Cookbook
Tool
Scenario

18 commands shown.

Scenario commands

18 commands

tcpdump / Setup

Find the right interface

List capture interfaces before starting a packet capture.

sudo tcpdump -D

Use the interface name with -i, such as eth0, ens5, en0, or any.

tcpdump / DNS

Capture DNS traffic

Watch DNS queries and replies on UDP or TCP port 53.

sudo tcpdump -i any -nn -vv 'port 53'

-nn avoids DNS and service-name lookups so tcpdump does not create extra resolver traffic.

tcpdump / Files

Capture packets to a pcap file

Save packets for later analysis in Wireshark or tshark.

sudo tcpdump -i eth0 -nn -s 0 -w capture.pcap 'host 192.0.2.10'

-s 0 captures the full packet instead of truncating after a small snap length.

tcpdump / Files

Read a saved pcap

Print packets from a capture file without touching the network.

tcpdump -nn -r capture.pcap

Add -tttt for readable timestamps or -X to include hex and ASCII payload output.

tcpdump / HTTP

Inspect HTTP requests

Capture cleartext HTTP traffic and print payload bytes.

sudo tcpdump -i any -nn -A -s 0 'tcp port 80'

This is only useful for unencrypted HTTP. HTTPS payload is encrypted.

tcpdump / TLS

Debug TLS handshakes

Capture TCP 443 traffic for handshake timing, resets, and retransmits.

sudo tcpdump -i any -nn -tttt 'tcp port 443'

tcpdump cannot decrypt TLS by itself, but it can reveal connection setup and packet loss patterns.

tcpdump / Host

Track one host

Capture all packets to or from a single IP address.

sudo tcpdump -i any -nn 'host 203.0.113.42'

Use src host or dst host when you only need one traffic direction.

tcpdump / TCP

Track one TCP conversation

Limit capture to a client/server pair and a single service port.

sudo tcpdump -i any -nn 'host 203.0.113.42 and tcp port 443'

This filter is a practical starting point for latency, reset, and retransmission debugging.

tcpdump / TCP

Show TCP flags

Find SYN, FIN, RST, and ACK behavior without dumping payload.

sudo tcpdump -i any -nn -tttt 'tcp[tcpflags] & (tcp-syn|tcp-fin|tcp-rst) != 0'

Useful when checking refused connections, resets, and handshake failures.

tcpdump / ICMP

Capture ICMP ping and errors

Watch echo requests, echo replies, unreachable messages, and TTL errors.

sudo tcpdump -i any -nn 'icmp or icmp6'

ICMP is often the quickest way to spot reachability and MTU-related symptoms.

tcpdump / L2

Find ARP resolution

Capture ARP requests and replies on a local Ethernet segment.

sudo tcpdump -i eth0 -nn -e 'arp'

-e prints link-layer headers, including source and destination MAC addresses.

tcpdump / DHCP

Capture DHCP negotiation

Watch DHCP discover, offer, request, and ack messages.

sudo tcpdump -i any -nn -vv 'udp port 67 or udp port 68'

Run this before renewing a lease so you see the full exchange.

tcpdump / Files

Rotate capture files

Keep a rolling capture without filling the disk with one huge file.

sudo tcpdump -i eth0 -nn -s 0 -G 300 -W 12 -w 'capture-%Y%m%d-%H%M%S.pcap'

-G rotates every 300 seconds and -W keeps a limited number of files.

dumpcap / Files

Use dumpcap for lightweight capture

Capture packets with Wireshark's capture engine and write pcapng output.

sudo dumpcap -i eth0 -s 0 -f 'host 192.0.2.10' -w capture.pcapng

dumpcap is usually better than the Wireshark GUI for long-running captures.

tshark / Files

Summarize a pcap with tshark

Read packets with Wireshark dissectors from the command line.

tshark -r capture.pcapng -Y 'dns or tcp.analysis.retransmission'

-Y is a Wireshark display filter. It is different from tcpdump capture filters.

tshark / Analysis

Extract selected fields

Print structured columns for quick shell-friendly analysis.

tshark -r capture.pcapng -T fields -e frame.time -e ip.src -e ip.dst -e tcp.stream

Add more -e fields to build quick reports from a pcap.

udpdump / UDP

Capture UDP packets through udpdump

Use Wireshark extcap input for UDP payloads sent to a local port.

udpdump --port 5555 --fifo /tmp/udpdump.pcap

udpdump is an extcap helper. It is most useful when integrated with Wireshark or extcap workflows.

tcpdump / Privacy

Capture only packet headers

Reduce payload exposure by limiting snap length.

sudo tcpdump -i eth0 -nn -s 96 -w headers-only.pcap

A smaller snap length can still expose metadata. Treat captures as sensitive data.

Capture vs display filters

tcpdump and dumpcap capture filters use BPF syntax before packets are saved. tshark -Y uses Wireshark display filters after packets are decoded.

Capture safety

Packet captures can contain credentials, tokens, hostnames, payloads, and internal IP addresses. Store and share pcap files carefully.

Start narrow

Begin with a host, port, or protocol filter. Broaden the capture only when the first trace does not include the traffic you need.

Tooling map

Which capture tool should you use?

tcpdump

Best first tool for quick captures, BPF filters, server terminals, and simple pcap files.

dumpcap

Good for long captures and pcapng output using Wireshark's capture engine without the GUI.

tshark

Best for reading pcap files, protocol dissection, display filters, and field extraction.

udpdump

Useful for Wireshark extcap workflows that convert UDP streams into capture input.