How to set up a firewall using FirewallD on CentOS 8

To set up a firewall using FirewallD on CentOS 8, you can follow these steps:

  1. Make sure FirewallD is installed on your system by running the command:
sudo yum install firewalld
  1. Start and enable the firewall service by running the commands:
sudo systemctl start firewalld
sudo systemctl enable firewalld
  1. To check the status of the firewall, use the command:
sudo firewall-cmd --state
  1. To add a new service to the firewall, use the command:
sudo firewall-cmd --add-service=service_name --permanent

Where service_name can be http, https, ssh, etc.

  1. To check the list of services currently allowed by the firewall, use the command:
sudo firewall-cmd --list-services
  1. To add a new port to the firewall, use the command:
sudo firewall-cmd --add-port=port_number/protocol --permanent

Where port_number is the port number you want to open and protocol can be tcp or udp.

  1. To check the list of ports currently allowed by the firewall, use the command:
sudo firewall-cmd --list-ports
  1. To reload the firewall configuration, use the command:
sudo firewall-cmd --reload

Note: The –permanent option makes the changes persistent across reboot. If you don’t want to make the changes permanent, you can skip this option.

Leave a Comment