A packet-capture lab with Wireshark and tcpdump

Install Wireshark and tcpdump, capture your own traffic safely, practise the display filters from the lessons on real packets, and use public sample captures for challenges.

  • Time: 30 minutes
  • Cost: free software, your own computer

What you need

Wireshark is the standard packet analyser and is free. The viewer you used in the lessons uses the same display-filter language, so filters such as ip.addr == 10.0.0.5 && tcp.port == 443 or dns.flags.rcode != 0 work unchanged. tcpdump and tshark do the same job from a terminal, which is how you capture on servers that have no screen.

Set it up

  • Windows: download the installer from wireshark.org and keep the option to install the packet-capture driver (Npcap) ticked.
  • macOS: download the Wireshark package from wireshark.org, or use Homebrew (brew install --cask wireshark). Allow the capture helper when asked.
  • Linux (Ubuntu): sudo apt install wireshark tshark tcpdump. When asked whether non-root users may capture, choose yes, then add yourself to the group: sudo usermod -aG wireshark $USER and log out and in again.

Start a capture by choosing your active interface (Wi-Fi or Ethernet) and pressing the blue shark fin. From a terminal: sudo tcpdump -i eth0 -w test.pcap and press Ctrl+C to stop; open the file in Wireshark. Use -c 100 to stop after 100 packets and add a filter like port 53 to limit what is recorded.

Check that it works

  1. Start a capture, then in a browser visit any website, then stop.
  2. Apply the filter dns. You should see your computer asking for the website’s name and getting an answer.
  3. Apply tcp.flags.syn == 1 && tcp.flags.ack == 0 and see the first packet of each connection.
  4. Right-click a TCP packet and choose Follow, then TCP Stream. For an HTTPS site the content is unreadable, which is exactly what you learned in the clear-text case.

If you see no interfaces, the capture driver or permissions are missing: reinstall with the driver, or fix the group membership above.

Practise safely

  • Only capture traffic you are entitled to see: your own computer and networks you own or administer. Capturing other people’s traffic, even on shared Wi-Fi, can be illegal.
  • Captures contain real data. Do not share a capture of your own browsing publicly; remove passwords and tokens first, and delete lab captures you no longer need.
  • To practise safely on plain HTTP, run your own small web server in a VM (see the Linux lab) and visit it from another VM.
  • Keep captures small: capture filters keep files manageable and your machine responsive.

Go further

  • Public sample captures are available from the Wireshark project’s wiki (search for “Wireshark sample captures”): open them and practise the filters on real traffic, including DNS, TCP problems and protocol oddities.
  • Recreate lesson cases yourself: capture a DNS lookup of a name that does not exist (NXDOMAIN), a TCP connection to a closed port (RST), and a download that you interrupt (resets and retransmissions).
  • Run a port scan against your own lab VM (never anyone else’s) and find it in the capture by looking at SYN packets to many ports.
  • Time a handshake: subtract the SYN time from the SYN/ACK time and compare two sites, as in the slow-page case.
  • Try the challenge sites that publish capture-based puzzles, after reading their rules and free offers.

Courses that use this lab

Other lab guides

Software changes quickly. Menu names and version numbers may differ a little from what you see; the ideas and the check at the end of each section stay the same. Always download from the project's own website, and read the licence terms for your situation.