Firewall - How to find and close a port in Linux

  • Last update: Apr 3, 2024
  • Views: 43
  • Author: Admin
Firewall - How to find and close a port in Linux

Colleagues hello to all.

In today's article, we'll talk about closing port on Firewall in Linux. Firewall is a special firewall that protects your server from outside threats by filtering incoming and outgoing traffic. Firewall minimizes the risk of virus and hacker attacks. When trying to connect to your server on any of the ports, then first this traffic will pass through the Firewall rules that you specify, and if the Firewall allows, then the connection will be successfully established.

Today we will close port 1521, this port is used to connect to the oracle database.

Related articles:

  1. How to disable Firewall in Linux
  2. Firewall - How to open a port in Linux

 

Article content:

  1. Find port 1521.
  2. Close the port.
  3. Checking the result.

 

STEP 1. Find port 1521.

In order for us to find the port that we want to close, first we need to find it in the Firewall rules. The command that shows the entire list of Firewall rules:

$. firewall-cmd --list-all

linux close port

The image shows that the ports field indicates that port 1521 is now open via the tcp protocol.


 

STEP 2. Close the port.

In order to close port 1521, we need to run a command that will remove this port from our rules.

$. sudo firewall-cmd --remove-port=1521/tcp --permanent

linux close port

As a result, after executing the command, you should have success.

 

And of course, do not forget to restart the service after each action with Firewall so that the new rules are applied.

$. sudo firewall-cmd --reload

linux close port


 

STEP 3. Checking the result.

After we have removed port 1521 from the Firewall rules, we need to make sure of this, for this we will use the same command to view all the rules.

$. firewall-cmd --list-all

linux close port

As you can see in the image, the ports field is empty, which means we succeeded.


 

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

SIMILAR ARTICLES

How to disable Firewall in Linux
Firewall - ufw status inactive on Ubuntu
Firewall - How to open a port in Linux