Netstat utility - find out what ports are listening in Linux
Colleagues hello to all.
In today's article, we'll talk about how to determine which program is listening on a particular port at the moment in Linux. For this purpose, there is a special utility called Netstat. A port in Linux is a logical entity and is directly associated with a process or service in the Linux operating system.
First, we need to install a utility called net-tools. If you don't have net-tools installed, then use the command:
$. yum install net-tools
I installed net-tools earlier, and Linux tells me that this package is already installed.
The first use of Netstat is to view all listening sockets (combinations of IP address and port), to do this, run the netstat command with parameters:
$. netstat -tulpan
In the following example, I started the database mariadb and postgresql on the server and run the same command again:
$. netstat -tulpan
And we see that two new ports have appeared, these are 3306 and 5432.
We can filter the results with the grep command.
In this example, we want to find out, for example, what ports the database uses MariaDB and PostgreSQL.
PostgreSQL
$. netstat -tulpan | grep "postgres"
MariaDB
$. netstat -tulpan | grep "mariadb"
Or vice versa, we want to know which program is listening on a specific port number.
PostgreSQL
$. netstat -tulpan | grep ":5432"
MariaDB
$. netstat -tulpan | grep ":3306"
Thank you all, I hope that my article helped you in some way.