Allow Port 80 & 443 in FirewallD

Using firewalld, you can allow/deny any port temporarily or permanently. The temporary allow/deny rules will be removed after the system reboot. But the permanent rules will persist even after the system restart.

The following commands allow incoming traffic on TCP ports 80 and 443 in firewalld.

sudo firewall-cmd --zone=public --add-port=80/tcp sudo firewall-cmd --zone=public --add-port=443/tcp

The --permanent option insures to remain firewall rules after system reboots.

sudo firewall-cmd --permanent --zone=public --add-port=80/tcp sudo firewall-cmd --permanent --zone=public --add-port=443/tcp

Next, apply the changes by reloading the firewallD.

sudo firewall-cmd --reload

View Firewall Rules

After adding the rules in firewalld, You can verify the by the running following command.

sudo firewall-cmd --permanent --zone=public --list-ports

Output:

443/tcp 8080/tcp

Remove Rules from FirewallD

If you don’t need to keep the ports open, you can remove/deny the above ports from the firewalld using the –remove-port option:

sudo firewall-cmd --permanent --zone=public --remove-port=80/tcp sudo firewall-cmd --permanent --zone=public --remove-port=443/tcp

Next, run the following command to apply the changes:

sudo firewall-cmd --reload