Every AlmaLinux server ships with firewalld, a dynamic firewall manager that controls which traffic reaches your services. Knowing how to configure firewalld on AlmaLinux properly — zones, services, ports and rich rules — is a core sysadmin skill: too open and you invite attacks, too closed and you lock yourself out. This guide explains the concepts first, then the exact commands to manage the firewall safely on AlmaLinux 9.
How Firewalld Works: Zones and States – How to Configure Firewalld on AlmaLinux
Firewalld organizes rules into zones — trust levels such as public (the default for new interfaces), internal and drop. Each connection belongs to one zone, and the zone decides which incoming traffic is allowed. Firewalld also keeps two configurations: the runtime config (active now, lost on reload) and the permanent config (loaded at boot). Changes made with --permanent only take effect after a reload — a design that lets you prepare rules safely.
Step 1: Check Firewalld Status – How to Configure Firewalld on AlmaLinux
sudo systemctl enable --now firewalld sudo firewall-cmd --state sudo firewall-cmd --get-default-zone sudo firewall-cmd --list-all
The last command shows everything allowed in the default zone: usually just ssh and dhcpv6-client on a fresh install.
Step 2: Allow Services and Ports
Prefer named services over raw ports — they document intent and include all needed port/protocol pairs:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload sudo firewall-cmd --list-services sudo firewall-cmd --list-ports
To see what a service definition includes, run firewall-cmd --info-service=http. When you configure firewalld on AlmaLinux for a custom application, raw ports are fine — just record why each is open.

Step 3: Manage Zones
If your server has two interfaces — one public, one on a private network — assign them to different zones:
sudo firewall-cmd --get-active-zones sudo firewall-cmd --permanent --zone=internal --change-interface=eth1 sudo firewall-cmd --permanent --zone=internal --add-service=samba sudo firewall-cmd --reload
Rules in the internal zone then apply only to the private interface, keeping file sharing off the public network entirely.
Step 4: Write Rich Rules for Fine-Grained Control
Rich rules extend the simple allow model. For example, allow SSH only from your office IP range, and drop everything else for that service:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" service name="ssh" accept' sudo firewall-cmd --permanent --remove-service=ssh sudo firewall-cmd --reload
Another common pattern is rate-limiting a service to slow down scanners:
sudo firewall-cmd --permanent --add-rich-rule='rule service name="ssh" limit value="3/m" accept'
Rich rules are evaluated in order, so review the full zone afterwards with firewall-cmd --zone=public --list-rich-rules.
Step 5: Removing Rules and Panic Mode
Remove entries with the matching --remove-* flags, always with --permanent plus a reload:
sudo firewall-cmd --permanent --remove-port=8080/tcp sudo firewall-cmd --reload
In an emergency, sudo firewall-cmd --panic-on drops all traffic instantly (your SSH session will freeze — that is the point), and --panic-off restores normal operation. Use it only when you have console access through your provider.
Comparing with Other Firewalls
Ubuntu users often meet the same concepts through UFW — our guide to installing and configuring UFW on Ubuntu shows the parallels. On older CentOS systems, many admins layered CSF on top of iptables; see how to install CSF on CentOS 7 for that approach. On AlmaLinux 9, native firewalld is the recommended, best-integrated option.
Troubleshooting
Changes disappear after reboot: you edited only the runtime config — repeat the change with --permanent. A service is allowed but unreachable: check the application actually listens (ss -tlnp) and that the interface is in the zone you edited. Locked out of SSH: connect via your provider’s console, then run firewall-cmd --add-service=ssh (runtime) to regain access and fix the permanent config. The official documentation at the AlmaLinux wiki links to deeper firewalld references.
Port Forwarding, Masquerading and Logging Dropped Packets
Two firewalld features matter once your AlmaLinux box routes traffic, for example as a gateway for containers or a small office network. Masquerading hides internal addresses behind the server’s public IP:
sudo firewall-cmd --permanent --zone=public --add-masquerade sudo firewall-cmd --reload
Port forwarding redirects an external port to an internal host — handy for publishing a service that lives on a VM or container:
sudo firewall-cmd --permanent --zone=public --add-forward-port=port=8443:proto=tcp:toport=443:toaddr=10.0.0.15 sudo firewall-cmd --reload
Finally, when you configure firewalld on AlmaLinux for a server under active probing, turn on drop logging temporarily to see what is being blocked:
sudo firewall-cmd --set-log-denied=all sudo journalctl -k | grep -i drop
Remember to set it back to off afterwards; on a busy public interface, logging every dropped packet can fill the journal surprisingly fast.
One last habit separates careful administrators from lucky ones: document your firewall. Keep a short note — a comment in a text file under /root or a page in your team wiki — listing every open service, why it is open, and when it was added. Firewall rules accumulate silently over years, and the note you write today is what lets you remove a stale rule confidently instead of leaving it forever “just in case”. Review the list whenever you add a service, and audit it against firewall-cmd --list-all at least twice a year.
Conclusion
To configure firewalld on AlmaLinux like a professional: think in zones, prefer services to ports, make changes permanent, and use rich rules when you need source restrictions or rate limits. With these habits, your firewall stays both tight and understandable — even months later at 3 a.m.