Firewalld is a dynamic firewall management tool that simplifies the process of controlling network traffic in Linux. This guide explains how to install, enable, and configure Firewalld across major Linux distributions.
Debian-Based Distributions
- Install Firewalld:
sudo apt install firewalld - Enable and start:
sudo systemctl enable firewalldsudo systemctl start firewalld - Check status:
sudo systemctl status firewalld
Red Hat-Based Distributions
- Install Firewalld:
sudo dnf install firewalld - For older versions:
sudo yum install firewalld - Enable and start:
sudo systemctl enable firewalldsudo systemctl start firewalld - Check status:
sudo systemctl status firewalld
Arch-Based Distributions
- Install Firewalld:
sudo pacman -S firewalld - Enable and start:
sudo systemctl enable firewalldsudo systemctl start firewalld - Check status:
sudo systemctl status firewalld
openSUSE-Based Distributions
- Install Firewalld:
sudo zypper install firewalld - Enable and start:
sudo systemctl enable firewalldsudo systemctl start firewalld - Check status:
sudo systemctl status firewalld
Basic Firewalld Configuration Commands
- Allow SSH (port 22):
sudo firewall-cmd --zone=public --add-service=ssh --permanentsudo firewall-cmd --reload - Allow HTTP (port 80):
sudo firewall-cmd --zone=public --add-service=http --permanentsudo firewall-cmd --reload - Allow HTTPS (port 443):
sudo firewall-cmd --zone=public --add-service=https --permanentsudo firewall-cmd --reload - Allow a specific port (e.g., 8080/tcp):
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanentsudo firewall-cmd --reload - Deny a specific port (e.g., 8080/tcp):
sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanentsudo firewall-cmd --reload - List all active rules:
sudo firewall-cmd --list-all - Reset all rules:
sudo firewall-cmd --runtime-to-permanentsudo firewall-cmd --reload
Important Notes
- Firewalld uses zones to manage rules. The default zone is public, but you can use others like home, work, or trusted.
- Always reload Firewalld after making rule changes.
- Use
--permanentto make rules persist after a restart; otherwise, they apply only to the current session.
By installing and configuring Firewalld, you gain a flexible and powerful way to manage network traffic on your Linux system. Its zone-based approach makes it adaptable to different environments and security needs.
Regularly reviewing your firewall rules ensures your system remains secure, efficient, and protected against unauthorized access.
Tags
Linux
