Introduction
Firewalld is a firewall management tool that is commonly used on Linux-based operating systems. A firewall is a security tool that monitors and controls the network traffic based on a set of rules.
Firewalld provides an interface for administrators to configure and manage the firewall on their system. It allows administrators to define rules that determine which traffic is allowed to enter or leave the system, based on criteria such as IP address, port number, and protocol.
In this article, we will explain to you how to set up a Firewall using firewalld in Centos 7.
Configure Firewall using Firewalld
- By default, Check if firewalld is installed.
# sudo systemctl status firewalld
- Install Firewalld by running the following command.
(Note: Execute this command only if the firewalld is not installed)
# sudo yum install firewalld
- Enable the firewalld service.
# sudo systemctl enable firewalld
- Start the firewalld service.
# sudo systemctl start firewalld
- Verify the status of the firewalld service.
# sudo systemctl status firewalld
Output
- Configure firewalld rules. You can add rules for specific ports, services, or sources.
For example: To allow SSH traffic on port 22, use the following command.
(Note: the# sudo firewall-cmd --zone=public --add-service=ssh --permanent
--permanent
flag saves the rules so they persist after a reboot.) -
Reload firewalld for the new rules to take effect.
# sudo firewall-cmd --reload
- Verify the new rule is active.
# sudo firewall-cmd --list-all
Output