Packets from different hosts can use the same TCP port, which makes a port alone a poor way to isolate one host's traffic. In Wireshark on the Linux desktop, you can combine display filters to show packets for one IPv4 address on either of two TCP ports.

Matching the address and port at either endpoint keeps traffic in both directions visible. The packet list can include TCP handshakes and acknowledgments as well as packets that carry application data.

Parentheses keep the port alternatives together so the address requirement applies to both. Without that grouping, the second port can match packets involving a different host.

Steps to combine display filters in Wireshark:

Start with a saved capture open in Wireshark, an empty display filter field, and the packet list and status bar in view. Use a capture with known matching and nonmatching packets, with the relevant IPv4 addresses readable in Source and Destination and numeric TCP ports readable in Info. The pictured capture, ~/Documents/captures/web-traffic.pcapng, contains two packets for 192.0.2.20 on each of TCP ports 80 and 443, plus traffic from another host and ICMP packets.

  1. Click the Apply a display filter field above the packet list.
  2. Enter a combined expression for your IPv4 address and two TCP ports in the Apply a display filter field.
    ip.addr == 192.0.2.20 && (tcp.port == 80 || tcp.port == 443)

    The address 192.0.2.20 and ports 80 and 443 are example values. ip.addr matches the source or destination IPv4 address. tcp.port matches the source or destination TCP port. && requires the address condition and the grouped port condition to hold for the same packet. || lets either port satisfy that group.

  3. Press Enter to apply the combined display filter.

    A green field signals valid syntax. The packet list updates when Wireshark finishes applying the expression.

  4. Compare the remaining address and port rows and the Displayed count with the matches you expect.

    Every remaining row should show your chosen address in Source or Destination and one of your chosen TCP ports in Info. Each chosen port with matching traffic in the capture should still have rows, and Displayed should equal the total number of expected matches. In the pictured capture, frames 1 and 2 show port 80, frames 3 and 4 show port 443, and the status bar reads Displayed: 4 (40.0%).

Share this guide