Configure firewalld on AlmaLinux and Rocky Linux
Updated 27 Nov 2026 firewall almalinux firewalld
Open services and ports permanently and check what is allowed.
Install and start
sudo dnf install -y firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --state
The default zone normally allows SSH. Confirm before continuing:
sudo firewall-cmd --list-all
Open a port or service
sudo firewall-cmd --permanent --add-port=20002/tcp
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Without --permanent, a rule lasts only until the next reload.
Restrict by source
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="198.51.100.7" port port="5432" protocol="tcp" accept'
sudo firewall-cmd --reload
Remove
sudo firewall-cmd --permanent --remove-port=20002/tcp
sudo firewall-cmd --reload
If a service still cannot be reached
Check that it listens on the right address with sudo ss -tlnp, and on shared-IPv4 plans that you are using a forwarded port.