Home CentOS/RHELHow to Configure Firewalld on RHEL 9 and CentOS Stream 9

How to Configure Firewalld on RHEL 9 and CentOS Stream 9

by Knowledge Base Linux
Configure firewalld shield protecting a RHEL 9 server illustration

Every RHEL 9 and CentOS Stream 9 server ships with firewalld, yet many administrators either disable it entirely or open ports without understanding how it works. Learning to configure firewalld properly gives you a powerful, zone-based firewall that is easy to audit and safe to change remotely. In this guide you will learn how to configure firewalld zones, services and ports, and how to write rich rules for fine-grained control.

Unlike editing iptables rules by hand, firewalld separates the runtime configuration from the permanent one. That design lets you test a change first and only keep it if you are not locked out — a lifesaver when you administer servers over SSH.

Prerequisites – How to Configure Firewalld on RHEL

  • A server running RHEL 9, CentOS Stream 9, AlmaLinux 9 or Rocky Linux 9
  • Root or sudo access
  • Basic knowledge of ports and services (SSH on 22, HTTP on 80, HTTPS on 443)

Step 1: Check the Firewalld Status – How to Configure Firewalld on RHEL

First, confirm the service is running and enabled:

systemctl enable --now firewalld
systemctl status firewalld
firewall-cmd --state

Then look at the current configuration of the default zone:

firewall-cmd --get-default-zone
firewall-cmd --list-all

The --list-all output shows the active interfaces, allowed services, open ports and rich rules — your complete firewall picture in one command.

Step 2: Understand Zones Before You Configure Firewalld

Zones are trust levels that you assign to network interfaces or source addresses. The ones you will meet most often are:

  • public — the default for new interfaces; only selected services are allowed
  • trusted — all traffic is accepted; use it only for isolated management networks
  • drop — everything incoming is silently dropped
  • internal / home / work — more permissive presets for private networks

List all available zones and inspect one in detail:

firewall-cmd --get-zones
firewall-cmd --zone=public --list-all

An interface belongs to exactly one zone at a time. Change the default zone only if you have a clear reason:

firewall-cmd --set-default-zone=public

Step 3: Open Services and Ports

Firewalld knows named services, which is cleaner than raw port numbers. Allow a web server and make it permanent:

firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-services

For applications without a predefined service, open the port directly:

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

Remember the golden rule when you configure firewalld: runtime-only changes (without --permanent) disappear on reload, while permanent changes need a --reload to become active. To test a risky change, apply it at runtime first, verify you can still connect, and only then re-apply it with --permanent.

Network zones diagram used when you configure firewalld on RHEL

Step 4: Write Rich Rules for Fine-Grained Control

Rich rules are the advanced language of firewalld. They let you filter by source address, log traffic, limit connection rates and more. For example, allow SSH only from your office network:

firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" service name="ssh" accept' --permanent
firewall-cmd --reload

Then remove the general SSH allowance so only that network can reach port 22:

firewall-cmd --zone=public --remove-service=ssh --permanent
firewall-cmd --reload

Rich rules can also rate-limit abusive connections, which is handy for public services:

firewall-cmd --zone=public --add-rich-rule='rule service name="http" limit value="25/m" accept' --permanent

List and remove rich rules with --list-rich-rules and --remove-rich-rule. For a different firewall approach on the same family, see how we install CSF on CentOS 7, and compare it with our guide to UFW on Ubuntu.

Step 5: Block an Abusive IP Address

To reject all traffic from a single hostile address, add a rich rule with the drop action:

firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="198.51.100.77" drop' --permanent
firewall-cmd --reload

Verify everything you have configured:

firewall-cmd --zone=public --list-all

Step 6: Save Runtime Rules and Review the Permanent Configuration

One elegant firewalld feature deserves a place in every workflow: if you tested a set of runtime rules and everything still works, convert them into the permanent configuration with a single command instead of re-typing them:

firewall-cmd --runtime-to-permanent

Finally, remember that the permanent configuration lives in /etc/firewalld/ while the defaults shipped by the package live in /usr/lib/firewalld/. If a zone file in /etc/firewalld/zones/ looks damaged, delete it and reload — firewalld falls back to the factory version, which is often the fastest way to recover from a badly hand-edited rule file.

Troubleshooting

My change disappeared after a reboot: you forgot --permanent. Runtime configuration is intentionally temporary.

I locked myself out of SSH: use the server console, run firewall-cmd --zone=public --add-service=ssh --permanent and reload. In the worst case, systemctl stop firewalld restores open access temporarily while you fix the rules.

A service is listening but unreachable: check with ss -tulpn that the application really listens, then confirm the port or service is open in the zone assigned to that interface — a common mistake is editing a zone the interface does not use.

Conclusion

You now know how to configure firewalld the way it was designed to be used: zones for trust levels, named services for clarity, permanent changes applied with a reload, and rich rules for exceptions and rate limiting. Document your rules as you add them, audit --list-all regularly, and your RHEL 9 firewall will stay both secure and understandable. For deeper background, the official firewalld documentation covers every option in detail.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.