Several applications can send packets through the same network interface while you troubleshoot one connection. In Wireshark on the Linux desktop, a capture filter limits which packets the selected interface records.

Wireshark applies a capture filter as packets arrive. Packets outside the filter are left out of the capture file, so recovering that traffic requires a new capture. A display filter changes which recorded packets appear in the packet list.

The interface determines which traffic the filter can see. A request to a service on the same machine can use the loopback interface. A request to a service on another machine uses the interface that carries the route to that service.

Steps to set a Wireshark capture filter:

Start with no capture open, Wireshark's default window layout with the status bar visible, and the default pcapng capture format, which keeps the filter with the interface information. Have some traffic that matches your filter and some that falls outside it, both on the interface you want to capture. The worked example uses Loopback: lo and a local HTTP server on TCP port 80 whose host also answers pings. Its lab address is 192.0.2.20. To try the same filter, use a reachable HTTP URL and host address from your own test network.

Capture only traffic you have permission to record. Run Wireshark under your normal account with capture permission, such as membership in the wireshark group on Ubuntu. Protect saved captures because they can contain passwords, cookies, and private data.

  1. Open Wireshark from the app launcher.
  2. Select the interface that carries your test traffic on the Welcome to Wireshark screen.

    A single click selects one interface, such as Loopback: lo in the example.

  3. Open the Capture menu.
  4. Choose Options….
  5. Click the Capture filter for selected interfaces field on the Input tab.
  6. Enter the capture filter for your traffic, replacing any existing value.

    The example uses tcp port 80, which matches TCP packets with port 80 as the source or destination. The field turns green when Wireshark accepts the libpcap filter syntax.

  7. Click Start to begin the filtered capture.

    The title begins with Capturing from when Wireshark is ready for traffic.

  8. Open a terminal on the same Linux desktop.

    On Ubuntu, Ctrl+Alt+T opens the terminal.

  9. Generate traffic on the selected interface that matches your filter.

    For tcp port 80, replace http://192.0.2.20/hello.txt with a plain HTTP URL served on TCP port 80 and reached through the selected interface. The command curl -fsS http://192.0.2.20/hello.txt returns Hello, world from the example server.

  10. Generate traffic on the same interface that falls outside your filter.

    For tcp port 80, replace 192.0.2.20 with the address of a host that answers pings through the same interface. The command ping -c 1 192.0.2.20 sends one ICMP echo request. A reply confirms that the test produced traffic the filter should exclude.

  11. Return to the Wireshark window.

    Alt+Tab returns to Wireshark when it was the preceding window.

  12. Click the red square Stop button on the toolbar.

    The Capturing from prefix disappears from the title when the capture stops.

  13. Click the display filter field above the packet list.
  14. Enter the display-filter form of your capture filter, replacing any existing text.

    The example uses tcp.port == 80. For the IPv4 capture filter ip host 192.0.2.20, the display form is ip.addr == 192.0.2.20. A protocol name such as icmp is the same in both syntaxes. These pairs match the same packets for plain traffic like the test requests, without tunnels or IP fragments. The field turns green when Wireshark accepts the display filter expression.

  15. Press Enter to apply the display filter.
  16. Confirm that the status bar's Displayed count equals its Packets count.

    The example shows Packets: 10 and Displayed: 10 (100.0%), with the HTTP request and response and no ICMP packets. With plain test traffic, a lower Displayed count means a recorded packet falls outside the expression.

  17. Press Ctrl+Alt+Shift+C in Wireshark to open Capture File Properties.
  18. Scroll down in Details to the Interfaces table.
  19. Verify that the Capture filter entry for your interface matches the expression you entered.

    The example shows tcp port 80 for Loopback. In Statistics, Captured and Displayed both show 10 packets.

Share this guide