Find which process is running on given port number

You can also use the same invocation you’re currently using, but remember to sudo

root@localhost:~# sudo netstat -nlp | grep :80
tcp6 0 0 :::80 :::* LISTEN 867/apache2

One of the oldest approach is using lsof command (gives list of open files)

$ sudo lsof -n -i :80 | grep LISTEN
root@localhost:~# sudo lsof -n -i :80 | grep LISTEN
apache2 867 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 946 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 2000 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 2208 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 2209 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 2218 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 2237 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 2240 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 5298 root 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 27322 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)
apache2 29335 www-data 4u IPv6 30403 0t0 TCP *:http (LISTEN)

In modern Linux there is a ss command which can be used to figure out the process, better to use with sudo access.

root@localhost:~# sudo ss -lptn 'sport = :80'
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 :::80 :::* users:(("apache2",29335,4),("apache2",27322,4),("apache2",5298,4),("apache2",2240,4),("apache2",2237,4),("apache2",2218,4),("apache2",2209,4),("apache2",2208,4),("apache2",2000,4),("apache2",946,4),("apache2",867,4))

Leave a Reply

Your email address will not be published. Required fields are marked *