← Module 09 · Operations & Troubleshooting

Packet Capture: Wireshark & tcpdump

A trace is evidence from one place and time. Learn to read what it shows without inventing what it cannot see.

Short answer: tcpdump records or prints packets selected by a capture filter; Wireshark decodes saved or live traffic and filters the view. Start with one question, choose a vantage point that can observe it, bound the collection, then correlate packet fields and timing with endpoint logs.

Read the troubleshooting workflow, TCP connection setup, and sequence and acknowledgment numbers.

A finish-line camera has a limited view

A race camera records who crosses one line. It cannot prove what happened around an unseen bend, and a dropped video frame can hide a runner who really passed. A packet capture has similar limits: the interface is the camera position, the capture filter selects what gets recorded, the display filter selects what you review, and timestamps put observations in order. A pcap or pcapng file is a recording, not an omniscient map of the network.

Choose the vantage point

Capture locationGood questionBlind spot
Affected client interfaceDid this host attempt a SYN or DNS query, and did a reply reach this capture point?Host capture hooks and offloads may differ from the actual wire
Server interfaceDid the request arrive, and was a response observed leaving?A load balancer may be the client's TCP peer; NAT changes tuples
Approved SPAN/mirror port or TAPWhat crossed this switch port or physical link?Mirror oversubscription, direction settings, and VLAN-tag handling can omit or alter observations
Supported Wi-Fi monitor interfaceWere there management frames, retries, or channel-specific RF events?Hardware, channel selection, encryption, and OS support limit visibility

Promiscuous mode doesn't make a switch send your laptop all other ports' unicast traffic. A Wi-Fi capture in ordinary associated mode may show Ethernet-like traffic without the 802.11 management frames needed for roaming analysis. The finish-line camera must be aimed at the relevant lane.

Capture filters and display filters are different languages

IntentCapture filter (libpcap)Wireshark display filter
One IPv4 peer on TCP 443host 192.0.2.20 and tcp port 443ip.addr == 192.0.2.20 && tcp.port == 443
Classic DNS on port 53port 53dns
ARParparp
Initial SYN without ACKip and tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn (IPv4)tcp.flags.syn == 1 && tcp.flags.ack == 0

The columns express similar questions, not universally identical packet sets. dns depends on dissection, whereas port 53 selects transport ports and excludes encrypted DNS on other ports. Display filtering doesn't remove packets from the original recording. A capture filter does: you cannot recover a discarded SYN-ACK later by clearing the display filter.

A bounded Linux capture

Use only an authorized interface and target, an approved local storage location, and your organization's capture permissions. In this Linux example, eth0 and documentation address 192.0.2.20 must be replaced. GNU timeout stops after 30 seconds, or tcpdump stops after 1,000 matching packets, whichever happens first. This is not a command to run on an unrelated production interface.

tcpdump -D
sudo timeout 30s tcpdump -i eth0 -nn -s 128 -c 1000 -w handshake.pcap 'host 192.0.2.20 and tcp port 443'
tcpdump -nn -tttt -r handshake.pcap

-D lists interfaces; -nn keeps addresses and ports numeric; -s 128 retains at most 128 bytes per packet; -c limits packet count; -w writes raw packets; -r reads them later without live-capture privileges. A timeout exit status of 124 can mean the time limit was reached, not that the capture is unusable. GNU timeout isn't normally included with macOS.

A 128-byte snapshot is useful for a simple Ethernet/IPv4 TCP handshake, but can truncate tunneled headers or application data. Choose the snapshot length for the question. Even short snapshots can contain sensitive payload or names; they are not automatic anonymization. Wireshark on Windows typically uses Npcap, with interface, capture filter, and stop conditions selected in capture options. Don't run the whole GUI elevated when the supported capture-permission setup suffices.

Read one conversation from start to finish

Open the capture, identify the relevant source/destination address and ports, and isolate the conversation with a filter such as tcp.stream == 0. The stream number is assigned by Wireshark for that file, not a TCP header field. Inspect the packet list for order, the protocol tree for fields, and the bytes when a field's interpretation is in doubt.

The following synthetic client-side trace uses relative sequence numbers and contains no TCP payload. It is illustrative, not a measured benchmark or a complete tcpdump output.

Time (s)DirectionFlagsRelative SeqRelative Ack
0.000Client:51514 to server:443SYN0not set
1.000Client:51514 to server:443SYN (repeated)0not set
1.020Server:443 to client:51514SYN, ACK01
1.021Client:51514 to server:443ACK11
Client captureServer direction 0.000: SYN, Seq 0 No reply observed here during this gap 1.000: SYN, same Seq 0 1.020: SYN, ACK, Seq 0, Ack 1 1.021: ACK, Seq 1, Ack 1
Time runs downward, not to scale. Arrows show directions inferred from the client trace, not independent proof of arrival at the server.

A SYN consumes one sequence number, which explains Ack 1. The repeated SYN and delayed completion suggest a connection-establishment interruption. They don't prove whether the initial SYN, a reply, or capture evidence was lost. You also cannot confidently call the 20 ms interval the path RTT: the observed reply could be delayed from the original attempt. Capture at the server, align the observations, and compare logs before locating the fault. The one-second gap is illustrative, not a universal retransmission timer.

Check artifacts before blaming the wire

ObservationAlternative explanationDiscriminating check
Outgoing checksum marked invalidNIC checksum offload fills it after the host capture pointCompare a receiving-side or wire capture; don't disable offloads casually
Packets larger than the interface MTUSegmentation/coalescing offloads expose buffers unlike wire framesCheck capture placement and TSO/GSO/GRO behavior
Wireshark reports retransmission or unseen segmentReordering, midstream capture, or dropped capture packetsInspect sequence/ACK progression and capture-drop counters
Only one direction appearsAsymmetric routing, mirror settings, wrong interface, or an overly narrow filterVerify both directions are observable at that point

Two race cameras need comparable clocks before you subtract their timestamps. Likewise, synchronize capture hosts and account for clock offset and capture-hook timing. Nanosecond display precision doesn't imply nanosecond measurement accuracy. tcpdump's kernel-drop count concerns the capture mechanism, not end-to-end packet loss.

Encryption and responsible handling

TLS application data is encrypted; QUIC also encrypts much of its transport information. HTTPS traffic on UDP 443 won't appear in the TCP-only example. DNS over HTTPS won't appear in a port-53 capture. Packet timing, sizes, endpoints, and some handshake information remain useful, but visibility depends on protocol and encryption features. Use approved endpoint logs when payloads are unavailable.

MINIMIZE THE RECORDING

Capture only authorized traffic for the shortest useful interval. Limit scope and file size, protect the recording, and follow retention rules. A display filter or a blurred screenshot does not sanitize the underlying capture. Don't upload raw traces or TLS session secrets to public services.

Read TCP windows and loss recovery, DNS request/reply interpretation, and HTTP over TCP and QUIC.

Sources