3 Ways to Find Out Which Process Listening on a Particular Port in linux [ centos / redhat / ubuntu ]

3 Ways to Find Out Which Process Listening on a Particular Port

picture source : https://www.computeraudiophile.com/forums/topic/30634-the-true-experimental-tweak-thread/
 

tools : 

1. using netstat 

$ netstat -ltnp | grep -w ':80'
if your system didnot have "netstat" command, use this command to get netstat package.
#yum install net-tools

we can test each port which is running on which service.
 using pipe " | " , we can grep information about the port and its service.


About netstat - 
netstat (network statistics) is a command line tool for monitoring network connections both incoming and outgoing as well as viewing routing tables, interface statistics etc. netstat is available on all Unix-like Operating Systems and also available on Windows OS as well. It is very useful in terms of network troubleshooting and performance measurement. netstat is one of the most basic network service debugging tools, telling you what ports are open and whether any programs are listening on ports.
This tool is very important and much useful for Linux network administrators as well as system administrators to monitor and troubleshoot their network related problems and determine network traffic performance. This article shows usages of netstat command with their examples which may be useful in daily operation.

source from : https://www.tecmint.com/20-netstat-commands-for-linux-network-management/


2. using lsof 
$ lsof -i :80
if you dont have "lsof" command in your system or server. use this command to get lsof tool in your system.
#yum install lsof -y

using lsof command we can get information about the port and its service.
we use "i" tag with lsof to grep the port.
About lsof : 
lsof means ‘List Open Files’. Lsof is used to find all files that are open by a process that is running on the server.
lsof meaning ‘LiSt Open Files’ is used to find out which files are open by which process.
Source : https://globedrill.com/how-to-install-lsof-command-on-centos-rhel-fedora-7-servers/

3. Using fuser Command

$ sudo yum install psmisc -y

$ fuser 80/tcp
the output shows the PID of service port. the first PID is for master process and remaining PIDs are child process.
 using "ps" command we get the service name of that port using PID.
 combine result -
About fuser :
The fuser command is a very smart unix utility used to find which process is using a file, 
a directory or a socket. It also gives information about the user owning the process and 
the type of access. The fuser tool displays the process id(PID) of every process using the 
specified files or file systems.

How To Use The fuser Utility?

The man command can be used to see manual pages for any command, but the best way to learn something new, especially linux commands, is by going through real world examples and never stop typing commands in the terminal. Run the following command in your terminal to get information about the usage options of the fuser utility. We will be experimenting with the fuser utility on a Ubuntu 12.04 VPS. However, as long as you are running a linux distribution it should be okay.
please subscribe to my channel for more linux related stuff : https://www.youtube.com/channel/UCIS1OSSZ9HBmI_KDY_PSPfQ

Comments