Skip to content

Lesson 9 of 9 · 27m

Debugging with Real Captures: tcpdump and Wireshark

Stop guessing — capture packets safely, read TCP handshake and retransmission evidence, follow streams, and connect network truth to application logs.

When application logs disagree about what happened, the capture is the referee. It shows whether the peer connected, who closed, whether packets were retransmitted, and whether TLS even started. You do not need to become a network engineer, but you do need enough packet literacy to avoid burning days on imaginary application bugs.

Capture narrowly and deliberately

On Linux, tcpdump is the first tool:

sudo tcpdump -i any -nn -s0 -w app.pcap 'tcp port 8443 and host 203.0.113.10'

-nn avoids DNS and service-name resolution delays, -s0 captures full packets, and -w writes a pcap for later analysis. Narrow the filter. Capturing everything on a busy host creates large files, exposes sensitive payloads, and can affect production traffic.

Read the TCP lifecycle

client -> server SYN
server -> client SYN, ACK
client -> server ACK
client -> server PSH, ACK  payload
server -> client ACK
server -> client FIN, ACK

A SYN with no SYN-ACK suggests filtering, routing failure, or nobody listening. A SYN-ACK followed by client retransmissions may mean return-path trouble. Repeated retransmissions after data transfer point to loss or an overwhelmed peer. A RST is a hard refusal or abort, not a graceful close.

Wireshark turns sequences into stories

Open the pcap in Wireshark and use display filters rather than scrolling:

tcp.port == 8443 && ip.addr == 203.0.113.10
tcp.flags.reset == 1
tcp.analysis.retransmission
tls.handshake.type == 1

Right-click a packet and choose Follow → TCP Stream to reconstruct application bytes. This is invaluable for plaintext protocols and useless for correctly encrypted TLS unless you control session keys. Wireshark's expert information highlights retransmissions, duplicate ACKs, zero windows, and out-of-order packets.

Correlate clocks and identifiers

The capture timestamp is on the capture host. Application logs may use different clocks, containers, or time zones. Note the exact host and interface where you captured. Correlate with client IP, source port, request IDs, and connection open times. A five-tuple in the capture should correspond to one application connection log entry; if not, your logging is incomplete.

Encrypted traffic still tells you plenty

You cannot inspect TLS payloads, but you can inspect handshake timing, certificate exchange size, cipher negotiation, alerts, retransmissions, and who closed first. For controlled debugging, some clients support SSLKEYLOGFILE, which records session secrets for later decryption in Wireshark. Treat that file as highly sensitive: it can decrypt captured traffic.

Reproduce minimally

Once the capture identifies behavior — half-close, reset after large write, delayed ACK, TLS alert — reproduce it in a small Python client or server. Then fix the parser or lifecycle and keep the capture fixture. Network debugging becomes durable when observations become regression tests.

Field notes

  • Capture on both sides when possible; middleboxes can alter what one side never sees.
  • Ring buffers (tcpdump -C size -W count) prevent disk exhaustion during long incidents.
  • Capture authorization and personal data carefully; pcaps are sensitive production artifacts.
  • ss -tanp shows live socket states such as ESTAB, CLOSE-WAIT, and SYN-SENT.
  • A growing CLOSE-WAIT count usually means your application is not closing sockets after the peer finished.

Was this lesson helpful?

Sign in to rate