Tcpdump: Traffic between localhost:[src-port:dst-port]

tcpdump

I'd like to get http traffic between localhost:8081 and localhost:8080.

I need http headers and body.

I've tried some commands but everything is complicated and I don't quite figure out what I'm doing exactly.

Any ideas?

Best Answer

You can filter based on host using "host localhost" and you can filter based on ports using "tcp port 8081".

When combining them, you will have a filter like:

"host localhost and tcp port 8081 and tcp port 8080"
"host localhost and (tcp port 8081 or tcp port 8080)"

You can use first one for both ports to be TCP 8080 and 8081. You can use the second one for any port (source or dest) matching either 8080 or 8081.