Developer & Network Tools

Packet Capture With Wireshark for Beginners

Capture your own traffic with Wireshark, filter the noise and read a connection step by step.

Key takeaways

  • A capture shows what actually crossed an interface, which settles many arguments about what software did.
  • Capture filters limit what is recorded; display filters limit what you see, and their syntax differs.
  • Encrypted connections hide content but still reveal addresses, timing, sizes and some setup details.
  • Keep captures short and focused, and treat saved files as sensitive.
  • Only capture traffic you have permission to examine.

Wireshark is a free, open-source program that records the network packets passing through an interface and shows each one, layer by layer. With a short capture and a couple of filters, you can watch a name lookup, a connection being opened and an encrypted session starting.

Capture only on networks and devices you own or are explicitly authorized to examine. Traffic can contain other people's private information, and intercepting it without permission is illegal in many places.

What you see in a packet

Data on a network is split into packets, and each is wrapped in headers added by successive protocol layers. Wireshark takes those wrappers apart.

Layers inside one captured web packet
Frame Capture details: time, length, interface. Ethernet or Wi-Fi Source and destination hardware addresses. IP Source and destination IP addresses and hop limit. TCP or UDP Port numbers; for TCP, sequence numbers and flags. Application data DNS, HTTP, or encrypted TLS records. Frame Capture details: time, length, interface. Ethernet or Wi-Fi Source and destination hardware addresses. IP Source and destination IP addresses and hop limit. TCP or UDP Port numbers; for TCP, sequence numbers and flags. Application data DNS, HTTP, or encrypted TLS records.

If these layers are unfamiliar, the TCP/IP and OSI models give the map.

Installing and permissions

Download Wireshark from the project's official site or your operating system's package manager. On Windows the installer includes or offers Npcap, the driver that makes capturing possible. On macOS and Linux you may need to grant capture permission to your user. Follow the platform instructions instead of running the whole graphical program as an administrator.

On a managed work computer, ask first. Installing capture tools is often restricted by policy.

Your first capture

  1. Open Wireshark and look at the list of interfaces. A moving activity line shows which one carries traffic.
  2. Double-click that interface to start.
  3. Do one specific thing, such as loading http://example.com or running a name lookup.
  4. Press the red stop button.
  5. Save the file if you want to keep it.

The window has three panes: a list of packets, a tree of protocol fields for the selected packet, and the raw bytes. Clicking a field in the tree highlights its bytes.

Even a few seconds produces hundreds of packets from background software. That's what filters are for.

Capture filters and display filters

A capture filter is set before you start and decides what gets written down. It uses the BPF syntax shared with tcpdump:

host 192.0.2.10
port 53
tcp port 443 and host 192.0.2.10

A display filter is typed in the bar above the packet list and hides rows without deleting them. Its syntax is Wireshark's own:

dns
ip.addr == 192.0.2.10
tcp.port == 443
udp.port == 53
http.request
tls.handshake.type == 1
tcp.analysis.retransmission
tcp.flags.reset == 1

Combine terms with &&, || and !. The bar turns green when the syntax is valid. Right-clicking a field and choosing the apply-as-filter option writes the expression for you.

Two kinds of filter
Capture filter Set before capturing Unmatched packets are lost for good Syntax like: port 53 Keeps files small Display filter Change at any time Hidden packets remain in the file Syntax like: udp.port == 53 Best for exploring VS Capture filter Set before capturing Unmatched packets are lost for good Syntax like: port 53 Keeps files small Display filter Change at any time Hidden packets remain in the file Syntax like: udp.port == 53 Best for exploring

When unsure, capture broadly for a short period and narrow the view afterward.

Walking through a web visit

Filter on dns and you'll typically see a query for a name and a response with addresses. A DNS lookup explains the records. If you see none, the answer may have come from a cache, or your browser or system may be using encrypted DNS.

Next, find the TCP handshake to the server: a packet with SYN, a reply with SYN and ACK, then ACK. The time between the first two is a good estimate of round-trip delay. Over HTTP/3, you'll see QUIC on UDP instead.

For HTTPS, the TLS Client Hello follows. It commonly includes the server name in readable form, unless newer encryption of that field is in use. The rest of the session is encrypted.

Right-click a packet and choose Follow, then the TCP stream option, to see a whole conversation assembled in order. For plain HTTP you can read requests and responses as text, which makes it obvious why unencrypted protocols are risky.

Useful views beyond the packet list

The Statistics menu summarizes a capture without reading it row by row. Protocol Hierarchy shows what mix of protocols the file holds. Conversations lists pairs of addresses and ports with packet and byte counts, which quickly reveals who is sending the most. Endpoints does the same per address. The I/O graph plots volume over time, so bursts and pauses stand out.

The time column can be changed from time since the capture began to time since the previous displayed packet. With a filter on one connection, large values then point straight at the delays. You can also add any protocol field as its own column, for example the DNS query name, by right-clicking it in the detail tree.

TCP sequence numbers are shown relative to the start of each connection by default, which makes them far easier to follow. The expert information window gathers retransmissions, resets and malformed packets in one list.

A worked example

Say a hypothetical internal page takes ten seconds to appear. You capture while loading it, then filter on dns. The first query goes to one resolver and gets no reply. Five seconds later your computer asks a second resolver, which answers at once. The page then loads quickly.

The capture has located the delay: an unresponsive first DNS server. Without it you might have blamed the web server. The fix is to repair or remove that resolver in the network settings, which you can check with nslookup or dig.

The same method works elsewhere. Reproduce the problem once, find the longest gap, and ask who was supposed to send the next packet.

Spotting common problems

  • SYN packets repeated with no reply: something is dropping traffic, or the host is unreachable.
  • SYN answered by a reset: nothing is listening on that port, or a device is rejecting the connection.
  • Retransmissions and duplicate acknowledgments: packets are being lost or reordered.
  • A long gap between request and first response byte: the server or something behind it is slow.
  • Zero window notices: a receiver can't accept data as fast as it arrives.
  • DNS queries with no answers or error codes: a resolution problem.

Wireshark's color coding and its expert information summary highlight many of these. Treat warnings as hints. For example, captures taken on the sending machine often show checksum errors because the network card fills in checksums after the capture point.

What you won't see

On a switched wired network, your computer mostly receives its own traffic plus broadcasts and multicast. Wi-Fi capture has further limits that depend on hardware, drivers and encryption. That's by design.

Modern encryption means page contents, passwords sent over HTTPS and messages in most apps aren't readable in a capture. Tools exist to decrypt your own test sessions using keys your own software exports, but that is an advanced debugging technique with obvious sensitivity.

Command-line capture

On servers without a screen, tcpdump records packets, and tshark is Wireshark's terminal companion.

sudo tcpdump -i any -c 100 -n port 53
sudo tcpdump -i eth0 -w capture.pcap host 192.0.2.10
tshark -r capture.pcap -Y dns

-c stops after a number of packets, -n skips name lookups, and -w writes a file you can open later in Wireshark. Replace the interface name with yours.

Where to capture from

Position decides what you can learn. A capture on the client shows what it sent and what reached it. A capture on the server shows the other side. If a packet appears in the first and never in the second, it was lost or blocked in between. Taking both at the same time, with accurate clocks, is one of the strongest diagnostic methods available.

To examine a device that can't run capture software, such as a printer or smart plug that you own, some managed switches offer port mirroring, which copies one port's traffic to another where your computer listens. Some routers can also save a capture themselves. Check your equipment's documentation, and turn mirroring off when you finish.

Long captures grow quickly and make Wireshark sluggish. Limit them with a capture filter, or configure the capture options to rotate through a fixed number of files so that an intermittent fault can be caught without filling the disk.

Handling captures responsibly

A capture file can contain session cookies, internal host names, email addresses and any data sent without encryption. Store it somewhere protected, share it only with those who need it, and delete it when the problem is solved.

Before sending one to a vendor or a forum, filter down to the relevant packets and export only those. Even then, review what remains. For public sharing, a sample captured on an isolated test network is far safer than a trimmed copy of real traffic.

Where to go next

Practice on traffic you understand. Run a single ping, a single lookup and a single curl request, and match each packet to what you did. Once the ordinary looks familiar, the unusual stands out much faster. A home lab gives you a safe place to break things on purpose and watch what happens.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Developer & Network Tools →

Latest news on this topic