Verification of listening ports in linux systems

The Internet has not been a safe place for a long time, it is worth seeing for whom we leave the door open and what it leads to. Ports are such an equivalent of doors in computer networks.

When we know what applications we use, we'll then know what to add to our own iptables firewall rules or UDP whitelist:

How to do it?

On most systems, the command is sufficient:

How to read it?

At first it seems like an Italian pasta dish, but it is enough to take a closer look that the result of this command is a mine of knowledge

After this result, we can conclude that this system is running MySQL and MongoDB.

You have MySQL:

MySQL uses the port by default 3306 and it is quite a known application for many years, so the application immediately tells us that it is the port used by MySQL instead of the port number

Do you have MongoDB:

Mongo is less known and much younger, this is where the port is displayed to us 27017.

We can also use netstat -ln, then we will get a list of all ports without detecting what is what.

Both apps have localhost: in front of the port so they only listen locally, that is, they cannot be accessed from outside via the network. It is a safe solution because it is better not to give strangers access to our database, even if it is password-protected.
For example, if we allow access from outside, it may turn out in the future that there is a loophole that allows you to log in without a password and we will forget about the update and the problem is ready.

Here we can see an SSH server listening on a standard port:

It is exposed outside, but SSH is a proven application and somehow we also have to get to the server, so do not worry too much as long as we have a long and randomly generated password or log in with a pair of keys (public and private).

We also have a curiosity at the bottom:

It is a port, but not really. It is a socket (plug) which allows the application to connect not via a standard network address but via a file. Some applications support connecting through UNIX sockets, and here's an example of that. These files are not exposed to the world in any way, they are a good solution to connect services on one server with different users because you can change user permissions to this resource like any other file on the disk.

It does not work!

If we do not have such a command in the system as netstat, you need to install the package net-tools.
In the case of Debian and derivatives e.g.. Ubuntu just execute these commands to install it:

Sufficient for CentOS and other RHEL derivatives:

How useful this post was?

Click on the star, to evaluate it!

Average grade / 5. number of votes:

So far, no votes! Be the first to rate this post.