Netstat utility - find out what ports are listening in Linux

  • Last updated: Nov 3, 2023
  • Views: 535
  • Author: Admin
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

How to check linux OS version

How to check linux OS version

lsof utility - find out what ports are listening in Linux

lsof utility - find out what ports are listening in Linux

Download and install CentOS 8

Download and install CentOS 8