Thursday, October 1, 2009

How to find out which process is listening upon a port

For standard processes, Services names can be seen in /etc/services files associated with port numbers. This is pretty much standard TCP/IP.

For non-standard user defined services,

lsof -i :port_number

For example:

So to see which process is listening upon port 80 we can run:

root@mystery:~# lsof -i :80
This gives us the following output:

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
apache2 10437 root 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10438 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10439 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10440 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10441 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 10442 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 25966 www-data 3u IPv6 22890556 TCP *:www (LISTEN)
apache2 25968 www-data 3u IPv6 22890556 TCP *:www (LISTEN)

No comments: