1. Using netstat Command

netstat (network statistics) command is used to display information concerning network connections, routing tables, interface stats and beyond. 

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:

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

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.

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


To find the process/service listening on a particular port, type (specify the port).

$ lsof -i :80


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:

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

You can find the process/service listening on a particular port by running the command below (specify the port).

$ fuser 80/tcp


Then find the process name using PID number with the ps command like so.

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

Done. 


這篇文章有幫助嗎? 2 Users Found This Useful (72 Votes)