Network Security In progress
Beginner 18 min read Network Security
Packet Analysis with tcpdump and Wireshark
Learn to inspect raw network traffic with tcpdump and Wireshark so you can see exactly what travels across a link, where it is going, and whether it is expected.
tcpdumpWiresharkpacket capturenetwork analysispcapthree-way handshake
Introduction
What is this?
Packet analysis means capturing the bytes that cross a network interface and reconstructing the conversation: source, destination, protocol, flags, payload, and timing.
Motivation
Why do you need it?
- You cannot defend what you cannot see; captures reveal the actual behavior of hosts for better than config files.
- Many attacks (scanning, beacons, exfiltration) have distinctive packet signatures even when the payload is encrypted.
- tcpdump and Wireshark ship with every Linux distribution and run in pure CLI or GUI — they are the universal first tool.
Think about it
Mental model
Imagine
Network traffic
Think of
Mailroom security footage
A camera doesn't read every letter, but it catches who walks in, how often, and what they carry.
Mechanics
How it works
- The capture card places the interface in promiscuous mode to read frames not addressed to it (on your own segment).
- tcpdump reads raw frames and applies a BPF filter before much of the decode, keeping CPU and disk cost low.
- Each captured frame is timestamped and stored in pcap format; Wireshark then decodes the stack (Ethernet -> IP -> TCP/UDP -> payload).
- Non-root group membership (pcap) allows capture without full root privileges.
Anatomy of a TCP conversation as seen in a capture
FrameEthernet header with MAC addresses
IPsource and destination addresses, TTL, protocol
TCPports, sequence numbers, SYN/ACK flags
Payloadthe actual HTTP/SSH/DNS bytes
Timingdelta tells you about latency and retries
Real world
In production
- A network engineer captures loopback traffic to prove an app misbehaves before blaming the firewall.
- A SOC analyst greps a pcap for reverse-DNS beacons to devices it should never contact.
- An SRE snapshots a packet-burst window during an outage and replays it in Wireshark to find the retransmit storm.
Guidelines
Best practices
- Capture to file with a rotate size (e.g. -C 100 -W 10) so you never fill the disk.
- Apply capture filters up front — host, port, tcp — then read with display filters.
- Use the 'no-promiscuous' flag on switches/VM bridges you don't own; promiscuous mode without permission is a policy issue.
- Correlate timestamps with server logs (same NTP source) so an incident timeline lines up.
Watch out
Common mistakes
- Capturing Gbps of everything 'just in case' and having no disk or patience to read it.
- Forgetting -i lo when troubleshooting a same-host app, then seeing nothing.
- Reading only the payload and ignoring the retransmission flags that expose the real fault.
- Sharing captures that contain credentials or PII on a public paste site.
When things break
Debugging tips
- Run tcpdump with -n to skip DNS lookups — resolution noise hides your signal.
- If the packet count is 0, check the interface name (ip link) — eth0 vs ens33 confuses everyone.
- Filter HTTP verbs with 'tcp port 80 and tcp[((tcp[12] & 0xf0) >> 2):4] = 0x47455420' or just use -A on a small capture.
Security
Security considerations
- Capturing on the wire is a surveillance power: only capture links you own or have written permission to monitor.
- Strip credentials before sharing pcaps; redact hashes/she knew them as metadata.
- Promiscuous mode can degrade performance on busy switches and violates segmentation assumptions if used on a shared segment.
Interviews
Interview checkpoint
Practice
Hands-on lab
Capture and Decode a Loopback HTTP Conversation
30 min · beginner
Objectives
- Run your first tcpdump capture against a local web server.
- Read the three-way handshake and an HTTP request/response pair.
- Save a pcap and confirm it opens cleanly.
Capture and Decode a Loopback HTTP Conversation
30 min · beginner
0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself
Quick quiz
0/2
1
Which tcpdump flag suppresses hostname and service name resolution?
2
In a TCP handshake capture, the final 'ACK' segment has which flags set?
Go deeper