How To Install FirewallD on CentOS Stream 9
In this tutorial, we will show you how to install FirewallD on CentOS Stream 9. FirewallD is a dynamic daemon that manages firewalls with support for network zones. It provides a flexible and robust firewall solution that is both user-friendly and powerful, making it an essential tool for securing CentOS Stream 9 systems.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the FirewallD on CentOS Stream 9.
Prerequisites
- A server running one of the following operating systems: CentOS Stream 9.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection.
- You’ll need administrative privileges or root access on your CentOS Stream 9 system. If you don’t have them, reach out to your system administrator.
Install FirewallD on CentOS Stream 9
Step 1. First, it’s crucial to ensure your system is up-to-date. Use the following command to update your system:
sudo dnf clean all sudo dnf update
This command will update all the installed packages on your CentOS system.
Step 2. Installing FirewallD on CentOS Stream 9.
Once your system is updated, you can install FirewallD using the following command:
sudo dnf install firewalld
This command will install FirewallD and all its dependencies.
After installing FirewallD, you need to enable it to start on boot. Use the following command:
sudo systemctl enable --now firewalld
This command will enable FirewallD to start at boot and start the service immediately.
To verify that FirewallD is running correctly, use the following command:
sudo firewall-cmd --state
If FirewallD is running correctly, this command will return “running”.
Step 3. Understanding FirewallD Configuration.
FirewallD configuration involves understanding several concepts:
- Zones: These define the level of trust for network connections or interfaces. They are used to control the traffic that is allowed to a network interface.
- Services: These are predefined sets of rules that specify the necessary resources for a particular service to function correctly.
- Rules: These are specific definitions of what traffic should be allowed or denied to a service or zone.
Step 4. Configure FirewallD.
Configuring FirewallD involves adding and removing services, opening, and closing ports, and changing the default zone. Here are some examples:
- To add a service to a zone, use the following command:
sudo firewall-cmd --zone=public --add-service=http --permanent
This command adds the HTTP service to the public zone permanently.
- To remove a service from a zone, use the following command:
sudo firewall-cmd --zone=public --remove-service=http --permanent
This command removes the HTTP service from the public zone permanently.
- To open a port, use the following command:
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
This command opens TCP port 8080 in the public zone permanently.
- To close a port, use the following command:
sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent
This command closes TCP port 8080 in the public zone permanently.
- To change the default zone, use the following command:
sudo firewall-cmd --set-default-zone=home
This command sets the default zone to “home”.
After making changes to the firewallD configuration, you need to save and reload it. Use the following command:
sudo firewall-cmd --reload
This command reloads the FirewallD configuration, applying all the changes made.
Step 5. Testing FirewallD Configuration.
To ensure your FirewallD configuration is working as expected, you can test it. For example, to check the services allowed in the public zone, use the following command:
sudo firewall-cmd --zone=public --list-services
This command lists all the services allowed in the public zone.
Congratulations! You have successfully installed FirewallD. Thanks for using this tutorial to install FirewallD on CentOS Stream 9. For additional help or useful information, we recommend you check the official CentOS website.