3

On a Solaris 8 server, how do I find out what process is listening on a given port? The Windows implementation of 'netstat' offers the -o and -b switches, which show the owning process ID and name respectively. Is there an equivalent under Solaris?

6

lsof -i

Doesn't come installed by default, but you can get Solaris version from http://www.sunfreeware.com/

4
  • Which netstat option provides the owning process under Solaris? I can't seem to find one in the man page? docs.sun.com/app/docs/doc/816-1055/6m7gh31ha?a=view May 8 '09 at 9:30
  • You're right, thought it's like Linux netstat. But in Solaris -p has different meaning.
    – vartec
    May 8 '09 at 9:43
  • +1 for lsof, definitely worth the trouble of installing. -i takes arguments of protocol and protocol:port, so you can do something like lsof -i TCP:25 to find out who's listening to 25/tcp (hopefully your mail server!)
    – jj33
    May 8 '09 at 12:18
  • Great answer, i'm never going to struggle with netstat -anp | grep again May 9 '09 at 14:56
4

If you don't want to or can't install lsof, you can also try the command pfiles. It prints out all the sockets open by a given process. If you had no other choice, you could iterate over all the PIDs and find the one listening to, say, port 25:

PORT=25
for p in $(ps -eo pid)
do
  OUT=$(pfiles $p)
  if [[ "$OUT" =~ port:\ ${PORT} ]]
  then
    echo $p
  fi
done

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.