Today in this short guide, we will show different ways of finding the process/service listening on a particular port in Linux.  This can be helpful if you need to know if there is a port conflict and what the other service/process is that's using it, lets begin.

Step 1: Using the netstat Command

The netstat (network statistics) command is used to display information concerning network connections, routing tables, interface stats and beyond. It is available on all Unix-like operating systems including Linux and also on Windows OS.

In case you do not have it installed by default, use the following command to install it.

$ sudo yum install net-tools #RHEL/CentOS
$ sudo apt install net-tools #Debian/Ubuntu
$ sudo dnf install net-tools #Fedora 22+

Once installed, you can use it with grep command to find the process or service listening on a particular port in Linux as follows (specify the port).  The flags used in this example:

l: tells netstat to only show listening sockets
t: tells it to display tcp connections
n: instructs it show numerical addresses
p: enables showing of the process ID and the process name

$ netstat -ltnp | grep -w ':80'

You should see something similar to the below:

tcp6       0      0 :::80                   :::*                    LISTEN      1438/apache2

Step 2: Using lsof command

$ sudo yum install lsof #RHEL/CentOS
$ sudo apt install lsof #Debian/Ubuntu
$ sudo dnf install lsof #Fedora 22+

To find the process/service that's listening on a particular port, execute the below command:

$ lsof -i :80

You should see something similar to the output below:

COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

apache2  1438     root    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2  8488 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2  8489 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2  8490 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2  8491 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2  8492 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2  9044 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2 10012 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2 14537 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2 14538 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)
apache2 14553 www-data    4u  IPv6  27962      0t0  TCP *:http (LISTEN)

Step 3: Using fuser command

The fuser command shows the PIDs of processes using the specified files or file systems in Linux.

To install fuser execute the following:

$ sudo yum install psmisc #RHEL/CentOS
$ sudo apt install psmisc #Debian/Ubuntu
$ sudo dnf install psmisc #Fedora 22+

To find the process/service name listening on a particular port execute the following command:

$ fuser 80/tcp

Then find the process name using the PID number with the ps command:

$ ps -p 2053 -o comm=
$ ps -p 2381 -o comm=