Netstat utility - find out what ports are listening in Linux

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

linux_netstat

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

linux_netstat

 

In the following example, I started the database mariadb and postgresql on the server and run the same command again:

$. netstat -tulpan

linux_netstat

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"

linux_netstat

 

MariaDB

$. netstat -tulpan | grep "mariadb"

linux_netstat

 

Or vice versa, we want to know which program is listening on a specific port number.

PostgreSQL

$. netstat -tulpan | grep ":5432"

linux_netstat

 

MariaDB

$. netstat -tulpan | grep ":3306"

linux_netstat


 

Thank you all, I hope that my article helped you in some way.

 

SIMILAR ARTICLES

tar utility - how to zip and unzip files in linux
tar utility - how to zip and unzip files in linux
LINUX
Read more
How to find out the size of a file and directory in Linux
How to find out the size of a file and directory in Linux
LINUX
Read more
bzip2 utility - how to compress and decompress files in Linux
bzip2 utility - how to compress and decompress files in Linux
LINUX
Read more