A port is a logical entity which represents an endpoint of communication and is associated with a given process or service in an operating system. we explained how to find out list of all open ports in Linux and how to check if remote ports are reachable using ‘nc’ command.
In this short guide, we will show different ways of finding the process/service listening on a particular port in Linux.
1. Using netstat Command
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.
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).
In the above command, the flags.
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.grep -w
– shows matching of exact string (:80).
2. Using lsof Command
lsof command (LiSt Open Files) is used to list all open files on a Linux system. To install it on your system, type the command below.
To find the process/service listening on a particular port, type (specify the port).
3. Using fuser Command
fuser command shows the PIDs of processes using the specified files or file systems in Linux.
You can install it as follows:
You can find the process/service listening on a particular port by running the command below (specify the port).
Then find the process name using PID number with the ps command like so.
You can also check out these useful guides about processes in Linux.
No comments:
Post a Comment