How to Find Process or Service Running on a Port in Linux


This guide shows how to find out the process or service running on a particular port on a Linux system.

In an operating system, once an application or program is successfully launched, it starts to run as a process and can listen to requests on a specific port. A service (sometimes referred to as a daemon) is a program that is normally intended to run in the background while listening on a specific port to serve other processes on the same host or on other hosts on a network.

Generally, services are automatically started at system boot time. Besides, a service can also run multiple processes, also known as threads.

Now let’s look at how to find which process or service is listening on a particular port, as explained below.

Using ss CLI Tool

ss is used to dump socket statistics, thus enabling you to view information about processes and the ports they are listening on. To find which service is listening on port 6443(replace it with the port you would like to check), you can run the following command.

In this command, the -l and -p options tell ss to only display listening sockets and the process name using the socket, respectively.

#ss -lp | grep 6443
Find process or service listening on a port using ss command

From the output of the command, the service or daemon running on port 6443 is the kube-apiserver (Kubernetes API server) which services REST operations, validates, and configures data for the api objects such as pods, services, replicationcontrollers, and others.

Using netstat CLI Tool

netstat is used to print network connections, routing tables, interface statistics, and more. It displays information in a similar fashion as ss. To find the service running on a port, run the following netstat command. Remember to replace the port with the one you intend to check:

#netstat -lp | grep 6443
Find process or service listening on a port using netstat command
Using lsof CLI Tool

lsof is a command-line tool used to list open files. An open file may be a regular file, a directory, a block special file, a character special file, a stream, or a network file such as a UNIX domain socket or more.

If you don’t have it installed by default on your Linux system, run the following command to install it. Remember to use sudo where necessary:

#apt update && apt install lsof  	#Debian/Ubuntu
#yum install lsof  			#RHEL/CentOS	
#dnf install lsof  			#RHEL/CentOS/Rocky Linux/Fedora 22+

Once you have the lsof package installed, you can use the following command to check the service running on a specific port. Here, the -i flag tells lsof to select the listing of files any of whose Internet address matches the address specified, in this case, only the port parameter is specified.

#lsof -i :6443
#lsof -i :6443 | grep LISTEN
Find process or service listening on a port using lsof command
Using fuser CLI Utility

Another useful command-line utility you can use to identify a daemon listening on a certain port is fuser. It helps to identify processes using files or sockets.

The fuser utility is provided by the psmisc package. In most cases, the psmisc doesn’t come pre-installed on most Linux distributions. To install it, run the correct command for your distribution:

#apt-get install psmisc 	#Debian/Ubuntu/Linux Mint/Raspbian/Kali Linux
#yum install psmisc		#RHEL/CentOS
#dnf install psmisc		#RHEL/CentOS/Rocky Linux/Fedora 22+
#pacman -S psmisc		#Arch Linux
#apk add psmisc		#Alpine

After the psmisc package is installed, you can run the fuser command below replacing port number 6443 with the port you would like to interrogate:

#fuser  -v  6443/tcp
Find process or service listening on a port using fuser command

In this guide, I have shown you how to find out the process or service running on a particular port on a Linux system, using various tools including ss and netstat. For any questions or comments, use the feedback form below.

You may also like...

Leave a Reply

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

Page Contents