Monday 21 August 2017

Find which process is listening on a port with LSOF


You can usually use the -p option in netstat to find out which process is listening on a specific port as follows:
netstat -anp | grep 22

This would provide something to the following which is telling you that port 22 has been opened for listening by process sshd who's PID is 954
tcp  0  0  0.0.0.0:22  0.0.0.0:*  LISTEN  954/sshd 

If you're in a fix and need a different method, good old fashioned LSOF can do the job 
lsof -i :22

Which would provide something similar to the following:
COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd     954    root    3u  IPv4  16348      0t0  TCP *:ssh (LISTEN)
sshd     954    root    4u  IPv6  16357      0t0  TCP *:ssh (LISTEN)




No comments:

Post a Comment