A port is a logical entity that represents an endpoint of communication and is related to a given course of or service in an working system. In earlier articles, we defined learn how to discover out the record of all open ports in Linux and learn how to examine if distant ports are reachable utilizing the Netcat command.
On this brief information, we are going to present alternative ways of discovering the method/service listening on a selected port in Linux.
1. Utilizing netstat Command
netstat (community statistics) command is used to show info regarding community connections, routing tables, interface stats, and past. It’s obtainable on all Unix-like working programs together with Linux and likewise on Home windows OS.
In case you would not have it put in by default, use the next command to put in it.
$ sudo apt-get set up net-tools [On Debian/Ubuntu & Mint] $ sudo dnf set up net-tools [On CentOS/RHEL/Fedora and Rocky Linux/AlmaLinux] $ pacman -S netstat-nat [On Arch Linux] $ emerge sys-apps/net-tools [On Gentoo] $ sudo dnf set up net-tools [On Fedora] $ sudo zypper set up net-tools [On openSUSE]
As soon as put in, you should use it with the grep command to seek out the method or service listening on a selected port in Linux as follows (specify the port).
$ netstat -ltnp | grep -w ':80'

Within the above command, the flags.
l
– tells netstat to solely present listening sockets.t
– tells it to show tcp connections.n
– instructs it to indicate numerical addresses.p
– permits exhibiting of the method ID and the method title.grep -w
– reveals matching of tangible string (:80).
2. Utilizing lsof Command
lsof command (Record Open Information) is used to record all open recordsdata on a Linux system.
To put in it in your system, sort the command beneath.
$ sudo apt-get set up lsof [On Debian, Ubuntu and Mint] $ sudo yum set up lsof [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/lsof [On Gentoo Linux] $ sudo pacman -S lsof [On Arch Linux] $ sudo zypper set up lsof [On OpenSUSE]
To seek out the method/service listening on a selected port, sort (specify the port).
$ lsof -i :80

3. Utilizing fuser Command
fuser command reveals the PIDs of processes utilizing the required recordsdata or file programs in Linux.
You’ll be able to set up it as follows:
$ sudo apt-get set up psmisc [On Debian, Ubuntu and Mint] $ sudo yum set up psmisc [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/psmisc [On Gentoo Linux] $ sudo pacman -S psmisc [On Arch Linux] $ sudo zypper set up psmisc [On OpenSUSE]
Yow will discover the method/service listening on a selected port by operating the command beneath (specify the port).
$ fuser 80/tcp
Then discover the method title utilizing PID quantity with the ps command like so.
$ ps -p 2053 -o comm= $ ps -p 2381 -o comm=

You can even try these helpful guides about processes in Linux.
That’s all! Are you aware of every other methods of discovering the method/service listening on a selected port in Linux, tell us through the remark type beneath.