CentOS 7.x Firewall: Enable/Disable and Add Ports

 

In CentOS 7.x, the default firewall is firewalld. Here is an example using CentOS 7.6

 

 

  1.  

1.To check the firewall status, run the command: `sudo firewall-cmd --state`

 

 

If the firewall status shows "not running," it means that the firewall is not enabled.

 

  1.  

2.To enable the firewall, you can use the following command: `systemctl start firewalld`.

 

 

"Running" indicates that the firewall is currently active and running.

 

3.disable the firewall, you can run the command: `systemctl stop firewalld.service`.

 

 

  1. 4.restart the firewall, you can run the command: `systemctl restart firewalld.service`.

  2.  

5.To view all open ports in the firewall, you can use the command: `firewall-cmd --zone=public --list-ports `. 

 

 

As shown in the above image, only port 13360 is open, which is the remote port number.

 

  1. 6.Open port 

firewall-cmd --zone=public --add-port=80/tcp --permanent # Open port 80

 

 

The return value "success" indicates that the port has been successfully opened.

 

7.firewall-cmd --reload # Make the configuration take effect immediately.

 

 

As shown in the above figure, please check all the open ports of the firewall. Port 80 is currently open.

 

8.firewall-cmd --zone=public --remove-port=80/tcp --permanent  #Close port 80. 

 

 

9.After closing port 80, check that port 80 is closed once the configuration takes effect.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to switch to a different repository for CentOS 8 EOL

 CentOS 8 reached its end of life at the end of 2021. When using yum repositories for...

To change the network interface name in CentOS 7.x

一.modify GRUB 1.Edit the GRUB configuration file by running the command: `vi...

To modify the hostname on CentOS

Method One:   1.Open a terminal or SSH into the Linux system. 2.Log in to the system with...

An incorrect configuration in the /etc/fstab file on the Linux system is causing login issues

Encountering communication issues with the machine, I checked the system error messages through...

How to use the atop monitoring tool in Linux

Atop is a monitoring tool used to monitor resources and processes in Linux systems. It...