Firewall - How to see open ports in Linux

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.

 

Related articles:

  1. How to disable Firewall in Linux
  2. Firewall - How to open a port in Linux
  3. Firewall - How to find and close a port in Linux

 

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

Linux - How to change the connection port number for SSH
Linux - How to change the connection port number for SSH
SAFETY
Read more
Firewall - How to find and close a port in Linux
Firewall - How to find and close a port in Linux
SAFETY
Read more
Firewall - How to open a port in Linux
Firewall - How to open a port in Linux
SAFETY
Read more