Firewall - How to see open ports in Linux

  • Last updated: Oct 12, 2024
  • Views: 9
  • Author: Admin
Firewall - How to see open ports in Linux

Colleagues hello to all.

In today's article, we'll talk about how you can quickly see open ports in Linux on the Firewall. Firewall is a program that provides reliable protection of your server by filtering incoming and outgoing traffic. In Linux Firewall is enabled by default and it is not recommended to turn it off, especially on a productive server.

 

We will check if a port on the Firewall is open with the help of firewall-cmd administrative tool.


 

First of all, we will check what ports are generally open by default on the Firewall in Linux, for these purposes we can use two commands:

First command:

$. firewall-cmd --list-all

linux firewall check open port

As a result of executing the command, the ports field is empty, which means that at the moment there are no open ports on the Firewall.

 

Second command:

$. firewall-cmd --list-ports

linux firewall check open port

This command displays a complete list of open ports, but since we currently have no open ports, the command will return an empty result.


 

Let's open a couple of ports as an example. Command to add ports on Firewall:

$. firewall-cmd --zone=public --add-port=1521/tcp --permanent

$. firewall-cmd --zone=public --add-port=3306/tcp --permanent

$. firewall-cmd --zone=public --add-port=5432/tcp --permanent

$. firewall-cmd --zone=public --add-port=80/tcp --permanent

$. firewall-cmd --zone=public --add-port=443/tcp --permanent

$. sudo firewall-cmd --reload

linux firewall check open port


 

After we have added the ports, now let's make sure that they are successfully enrolled in the Firewall rules.

$. firewall-cmd --list-all

linux firewall check open port

Now we have the ports that we added in the ports field.

 

$. firewall-cmd --list-ports

linux firewall check open port

And here we have a list of ports that we have added.

 

If we have a lot of open ports, then for easy searching we can use the grep command:

$. firewall-cmd --list-ports | grep 3306

linux firewall check open port


 

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

 

SIMILAR ARTICLES

How to check linux OS version
Firewall - ufw status inactive on Ubuntu