2

I've recently starting playing around with the Squid caching server on my OS X based computer. I'm curious if there's a way to tell which port Squid is running on using netstat or other standard unix commands.

That is, I know Squid runs by default on port 3128, but if I didn't know this or someone had started Squid listening on a different port via a configuration file I couldn't access or find, would there be a way to determine which port is was listening on.

Some rudimentary googling turning up the following netstat command for machines running Linux

$ netstat -plant

But running this on OS X threw an error

$ netstat -plant
netstat: lant: unknown or uninstrumented protocol

I assume this is some BSD/Linux difference, but not knowing my networking well enough, I don't have the ability to figure out what the correct BSD invocation would be.

OS 10.10 if that matters.

1

Listing the open files with -i should show you the ports in use

lsof -i

If there's too much output

lsof -i | grep squid

Works with Linux & OS X

  • Thank you for your answer -- but I'm afraid I'm not following it completely. If I run lsof -i and grep for squid, I get the following output (gist.github.com/astorm/5d238d26faa66de23851). This doesn't (seem to) mention port 3128 anywhere, and I'm sure squid is running on this port since I've been able to connect to it and use it. Am I misinterpreting the data somehow? – Alan Storm Oct 3 '15 at 22:17
  • And for anyone following along at home, lsof -i -P did the trick. – Alan Storm Oct 3 '15 at 22:31
  • 1
    Strange on our Ubuntu Squid server the -P is not needed, maybe an OS X thing or perhaps it's because we have active connections. Anyway, glad it pointed you in the right direction – Jon Rhoades Oct 3 '15 at 23:20
  • If you're curious -- BSD seems to have a concept of named ports -- without the -P the port name is shown -- with -P the numerical port is shown. – Alan Storm Oct 4 '15 at 0:10
1

In BSD netstat -p is protocol, whereas it is program in the netstat from net-tools, the BSD version appears to have no equivalent. man is almost always your friend in these cases.

BSD has sockstat which gets you what you want but this is does not appear to be there on the OS X I have access to.

As already mentioned lsof is probably your most cross platform way of getting the result you want. add -n to stop port numbers being converted to names and confusing you with ndl-aas where you are expecting 3128.

  • I know the -n specifics would have worked better in a comment, but for now I can only comment on my own posts. – DanSut Oct 3 '15 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.