Capture and Read Packets with Wireshark and tcpdump
Capture traffic on a lab interface, filter it precisely, follow a TCP conversation, and read DNS, HTTP, and TLS metadata without pretending encryption is gone.
By the end, you’ll be able to…
- Choose a capture interface and explain what a switched network does and does not show.
- Distinguish capture filters from display filters and write both.
- Use tcpdump for fast terminal captures and Wireshark for visual analysis.
- Follow a TCP stream and interpret DNS, HTTP, and TLS metadata.
- Preserve a capture as defensible evidence with timestamps and integrity checks.
01Capture Points, Interfaces, and Permissions
Packet capture copies frames that an interface sees. On an old hub, every frame reached every port. On a modern switch, each port normally receives only unicast traffic addressed to that port, plus broadcast and multicast. To see another host's traffic you need a mirror or SPAN port on the switch, a network TAP, or a capture agent on the endpoint itself. Wi-Fi adds another layer: a normal managed interface sees only traffic for its own association, while monitor mode can capture raw 802.11 frames.
Where you capture determines what you can prove. A capture on the client shows the request leaving and the response arriving, but not what the server actually received. A capture on the server shows the request as received, but not the loss or delay on the client side. A capture in the middle shows the path, but may show a proxy or NAT device rather than either endpoint. Write down the capture point before you analyse anything.
Capturing raw packets requires privilege. Running the whole Wireshark graphical application as root is a bad habit because a dissector bug could become a local privilege escalation. Prefer dumpcap with the minimum capabilities, or add your user to the appropriate capture group on your distribution. In a lab, capture inside the virtual machine rather than on the host, and keep the virtual network isolated from production.
# List interfaces as dumpcap and Wireshark see them.sudo dumpcap -D# Confirm addresses before choosing an interface.ip -brief address# Check whether your user can capture without sudo# (group membership varies by distribution).groupsgetcap /usr/bin/dumpcap 2>/dev/null1. eth0 2. lo 3. any lo UNKNOWN 127.0.0.1/8 eth0 UP 10.10.10.20/24 lab UP users /usr/bin/dumpcap cap_net_admin,cap_net_raw=eip
02Capture Filters and Display Filters Are Different Languages
A capture filter uses Berkeley Packet Filter syntax and is applied by the kernel before packets are written to disk. It is fast, it reduces file size, and it is permanent: packets rejected by the capture filter are never available for later analysis. The syntax is limited to link, IP, transport, and a few byte-offset expressions. A display filter is applied by Wireshark after capture and can address hundreds of protocol fields. It is flexible and non-destructive, but it cannot recover packets that were never captured.
Choose the capture filter around the scope of the investigation. If you only care about one host, capture that host. If you care about one protocol, capture that protocol. Avoid a filter so narrow that you lose the handshake, the DNS lookup, or the error response that explains the failure. A common compromise is to capture everything on a lab interface with a size limit, then filter during analysis; on a busy network, a broad capture can fill the disk quickly.
Display filters use field names, comparison operators, and boolean logic. ip.addr matches either source or destination; ip.src and ip.dst are directional. tcp.port matches either side; tcp.srcport and tcp.dstport are specific. You can combine expressions with and, or, and not, group them with parentheses, and test text with contains. The most common beginner error is typing capture-filter syntax into the display bar: tcp port 443 is valid BPF but invalid as a display filter, where the correct form is tcp.port == 443.
CAPTURE FILTER (BPF, applied before packets are saved)tcp port 443host 10.10.10.30 and not port 22net 10.10.10.0/24udp port 53icmptcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack == 0DISPLAY FILTER (Wireshark, applied to packets already captured)tcp.port == 443ip.addr == 10.10.10.30ip.src == 10.10.10.20 and tcp.dstport == 80dns.qry.name contains "example"http.request.method == "GET"tls.handshake.type == 1tcp.analysis.retransmissionframe.time >= "2026-11-01 09:00:00"03tcpdump: Fast Capture in the Terminal
tcpdump is the workhorse of command-line capture. The basic shape is tcpdump -i interface -nn -s0 -w file.pcap filter. -i selects the interface, -n stops DNS resolution, -nn stops both DNS and port-name resolution, -s0 captures the full packet instead of truncating it, -w writes a pcap file, -c stops after a number of packets, and -r reads a saved file. Add -tttt for human-readable timestamps, -e for link-layer headers, -A for ASCII payload, and -X for hex plus ASCII.
For live troubleshooting, read the output as a sequence. A SYN with no reply suggests filtering or an unreachable host. SYN, SYN-ACK, ACK means the connection opened. Repeated retransmissions suggest loss. A RST immediately after SYN means the port is closed or a middlebox rejected the connection. tcpdump's relative sequence numbers and flags are enough to reconstruct the conversation even when the application payload is encrypted.
For long captures, rotate files and bound the size. -G 3600 starts a new file every hour, -W 24 keeps 24 files, and -C 100 starts a new file at 100 million bytes. Write to a directory with enough free space and monitor it. If you are root, -Z tcpdump drops privileges after opening the capture device. Always record the interface, filter, start time, and command line; a pcap without context is much harder to defend.
# Five packets from one HTTPS conversation, no name resolution.sudo tcpdump -i eth0 -nn -c 5 'tcp port 443'# DNS queries and answers with verbose detail.sudo tcpdump -i eth0 -nn -vv 'udp port 53'# Full packets written to a file, with a one-hour rotation.sudo tcpdump -i eth0 -nn -s0 -G 3600 -W 24 -w 'lab-%Y%m%d-%H%M%S.pcap' 'net 10.10.10.0/24'# Read a saved capture and show HTTP requests in ASCII.tcpdump -nn -A -r lab.pcap 'tcp port 80'09:15:01.123456 IP 10.10.10.20.51342 > 203.0.113.10.443: Flags [S], seq 3894025134, win 64240, options [mss 1460,sackOK,TS val 123456 ecr 0,nop,wscale 7], length 0 09:15:01.124001 IP 203.0.113.10.443 > 10.10.10.20.51342: Flags [S.], seq 2213041210, ack 3894025135, win 65160, options [mss 1460,sackOK,TS val 998877 ecr 123456,nop,wscale 7], length 0 09:15:01.124210 IP 10.10.10.20.51342 > 203.0.113.10.443: Flags [.], ack 1, win 502, options [nop,nop,TS val 123457 ecr 998877], length 0
04The Wireshark Workflow
Wireshark is a graphical analyser built on the same capture engine as dumpcap. Start with Capture > Options, select the interface, and optionally set a capture filter. Reproduce exactly one action, stop the capture, and then use display filters to narrow the view. Starting with a huge capture and clicking randomly is slow and error-prone. A short, intentional capture around a known event is easier to explain and easier to defend.
The most useful analysis features are Follow TCP Stream, Conversations, Protocol Hierarchy, and Expert Information. Follow TCP Stream reassembles one direction and then the other, which makes an HTTP exchange readable and shows exactly what was sent. Conversations sorts by bytes and packets, which quickly reveals the loudest talker. Protocol Hierarchy shows the mix of protocols in the file. Expert Information flags retransmissions, duplicate ACKs, zero-window events, and malformed packets that may explain a symptom.
Use colouring and filtering together. Right-click a field and choose Apply as Filter to build accurate expressions instead of typing them by hand. Mark packets that matter, add comments, and save the working file as pcapng. When exporting evidence, use File > Export Specified Packets to create a smaller file containing only the relevant frames, then record the filter and the original file hash. Keep the original untouched and analyse a copy.
WIRESHARK WORKFLOW: ONE HTTPS REQUEST1. Capture > Options > select eth0.2. Set capture filter: tcp port 443. Start.3. Reproduce one request in the lab browser. Stop.4. Display filter: tls.handshake.type == 1 Inspect the ClientHello: SNI, supported versions, cipher suites.5. Display filter: tcp.flags.syn == 1 and tcp.flags.ack == 1 Confirm the server accepted the connection.6. Right-click a packet > Follow > TCP Stream. For TLS, expect record headers and ciphertext, not plaintext.7. Statistics > Conversations: identify the endpoints and byte counts.8. Statistics > Expert Information: note retransmissions or resets.9. File > Save As: lab-20261101-https.pcapng.10. Record interface, filter, time range, and Wireshark version.05Reading DNS, HTTP, and TLS Metadata
DNS is usually readable. The query name, query type, transaction ID, response code, answers, and TTLs appear in the packet details. A repeated query for the same name every few seconds may be a health check, a misconfigured client, or beaconing. A long random label under a domain can be DNS tunnelling, though it can also be a content delivery or anti-spam encoding. Look at volume and timing, not one packet.
Cleartext HTTP exposes the request line, Host header, User-Agent, cookies, and response headers. That is why HTTP is useful in a lab and dangerous in production. HTTPS protects those fields with TLS, but the handshake still exposes a lot: the ClientHello carries the server name indication in most deployments, the supported TLS versions, and the offered cipher suites. The ServerHello reveals the chosen version and cipher. The certificate is visible in TLS 1.2, while TLS 1.3 encrypts it unless you have the session keys.
Encryption limits are real. Without keys, you can see endpoints, timing, packet sizes, and some handshake metadata, but not URLs, cookies, or bodies. A key log file written by a client you control, through the SSLKEYLOGFILE environment variable, lets Wireshark decrypt that client's TLS 1.3 traffic in a lab. It does not decrypt anyone else's traffic. Never intercept or decrypt traffic on a network you do not own, and never treat metadata as proof of content.
# DNS names, response codes, and answer counts.sudo tcpdump -i eth0 -nn -vv 'udp port 53'# Cleartext HTTP request headers on a lab service.sudo tcpdump -i eth0 -nn -A 'tcp port 80'# TLS handshakes only: ClientHello and ServerHello.sudo tcpdump -i eth0 -nn 'tcp port 443 and (tcp[((tcp[12] & 0xf0) >> 2)] = 0x16)'09:20:14.882211 IP 10.10.10.20.54321 > 1.1.1.1.53: 41237+ A? example.com. (29) 09:20:14.899004 IP 1.1.1.1.53 > 10.10.10.20.54321: 41237 1/0/0 A 203.0.113.10 (45) 09:22:03.100011 IP 10.10.10.20.51400 > 10.10.10.30.80: Flags [P.], seq 1:78, ack 1, length 77 GET /lab HTTP/1.1 Host: lab.example.test
06Evidence, Timestamps, and the Limits of a Capture
A packet capture becomes evidence when you can say where it came from, when it was taken, and whether it changed. Record the capture host, interface, filter, tool version, start and end time in UTC, and the source of time synchronisation. Packet timestamps come from the capturing host's clock, so a host with drifting time produces a file that is hard to correlate with server logs. Check NTP before a capture that matters.
Hash the file as soon as the capture stops. sha256sum produces a fingerprint; store it separately from the pcap, and work on a copy. Preserve the original read-only. A hash does not prove the capture is complete or correct, but it detects later modification. Document any conversion, filtering, or export step, because an exported subset is a derived artefact, not the original evidence.
Every capture has blind spots. A switched network hides other hosts' unicast traffic. A mid-capture start misses the handshake. A truncated snaplen cuts off payload. Checksum offload can make valid packets look invalid because the NIC has not calculated the checksum yet. Encrypted traffic hides content, and a busy host can drop packets before they reach the capture buffer. State these limits in your notes instead of implying that the pcap is a complete recording of reality.
# Stop the capture first. Work in the evidence directory.date -u +"%Y-%m-%dT%H:%M:%SZ"sha256sum lab-20261101-https.pcapng | tee lab-20261101-https.pcapng.sha256stat -c '%n %s bytes modified %y' lab-20261101-https.pcapng# Keep the original read-only and analyse a copy.chmod 0444 lab-20261101-https.pcapngcp lab-20261101-https.pcapng analysis-copy.pcapng2026-11-01T11:04:22Z 3f9c2a7d1b4e6f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708 lab-20261101-https.pcapng lab-20261101-https.pcapng 482913 bytes modified 2026-11-01 11:03:58
The ideas worth keeping.
- Where you capture determines what you can see; a switch port does not show other hosts' unicast traffic by default.
- Capture filters are applied before storage and cannot be undone; display filters are flexible and non-destructive.
- DNS and HTTP expose useful detail, while TLS metadata gives endpoints and handshake facts but not content.
- Evidence needs UTC timestamps, tool versions, hashes, and an honest statement of the capture's limits.
Make it yours.
Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.
Exercise 1: Write the right filter for the question
You need to capture only TCP port 8080 traffic between 10.10.10.20 and 10.10.10.30 on interface eth0, excluding DNS and ARP. Write a capture filter and the equivalent display filter. Explain why the two are not interchangeable and one risk of making the capture filter too narrow.
Explore a worked solution
Capture filter: sudo tcpdump -i eth0 -nn 'host 10.10.10.20 and host 10.10.10.30 and tcp port 8080' (or dst host and src host variants if direction matters). Display filter: ip.addr == 10.10.10.20 and ip.addr == 10.10.10.30 and tcp.port == 8080. DNS and ARP are already excluded by the tcp port 8080 clause. The capture filter is compiled into BPF and applied before packets are saved, so rejected packets are gone forever. The display filter only hides packets that are already in the file and can be changed at any time. A narrow capture filter can discard the DNS lookup, the TCP handshake, or an ICMP error that explains why the connection failed; capture a little more context than you think you need when storage allows.Capture filters reduce what is stored; display filters change what is shown. The first decision is irreversible, so it deserves more care.
Exercise 2: Read a capture without decrypting it
A capture shows a SYN from 10.10.10.20:51500 to 203.0.113.10:443, a SYN-ACK, an ACK, a TLS ClientHello with SNI shop.example.com, a ServerHello selecting TLS 1.3 and TLS_AES_256_GCM_SHA384, and then only encrypted application data records. A user claims they downloaded a file from the site. What can you prove, what can you not prove, and what would you do next?
Explore a worked solution
You can prove that a TCP connection opened to 203.0.113.10:443, that the client requested shop.example.com in the TLS handshake, that TLS 1.3 with AES-256-GCM was negotiated, and that encrypted records were exchanged in both directions. You cannot prove which URL was requested, what the response contained, whether a file was downloaded, or whether the server is trustworthy, because the application data is encrypted. Next steps: correlate with browser history, proxy logs, DNS logs, endpoint file-creation events, and server-side logs for the same time window; check certificate and SNI consistency with the expected service; if this is a lab client you control, enable SSLKEYLOGFILE and repeat the test to decrypt the session. Do not attempt decryption on a network you do not own.Metadata answers who talked to whom and when, not what they said. Correlation with other sources is what turns a capture into a finding.
What stayed with you?
Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.
Keep exploring.
The official references behind this lesson, when you want a second angle or the full details.
One lesson closer.
Reading is a start. Trying it yourself makes the connection.