Monitoring multiple ports in tcpdump

NetworkingTcpdump

Networking Problem Overview


I am trying to find a way to read multiple ports using tcpdump. Suppose I have two ports, p1 and p2, and I want to read the traffic moving through both ports simultaneously. Is there any way to do it using tcpdump or will I have to use some other tool?

Basically I am running a proxy server which is running on some port. I want to read the traffic moving through this port as well traffic moving through port 80(HTTP).

Networking Solutions


Solution 1 - Networking

tcpdump port 80 or port 3128

or, alternatively,

tcpdump port '(80 or 443)'

Solution 2 - Networking

if you want to filter ports based on the range then use portrange.

E.g:

> tcpdump -an portrange 1-25

Solution 3 - Networking

You can also select an interface (change -i any to -i en0 for example) and the communication protocol :

tcpdump -i any 'udp port 1812 or tcp port 1813'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmawiaView Question on Stackoverflow
Solution 1 - NetworkingcafView Answer on Stackoverflow
Solution 2 - NetworkingDeiveegaraja AndaverView Answer on Stackoverflow
Solution 3 - Networkinglucas24007View Answer on Stackoverflow