Home Rocky LinuxHow to Configure Firewalld on Rocky Linux 9

How to Configure Firewalld on Rocky Linux 9

by Knowledge Base Linux
Configure firewalld on Rocky Linux 9 with a firewall wall

firewalld is the default firewall manager on RHEL-family systems, and learning to configure firewalld on Rocky Linux 9 is a core sysadmin skill. Unlike editing iptables rules directly, firewalld works with zones and named services, supports runtime and permanent configuration, and integrates cleanly with modern nftables backends. This guide covers everything from checking the current state to rich rules and troubleshooting.

Concepts You Need to Configure Firewalld on Rocky Linux 9

  • Zones define a trust level for a network connection: public (default, untrusted), home, internal, trusted and others.
  • Services are named bundles of ports, such as http (80/tcp) or ssh (22/tcp), defined in /usr/lib/firewalld/services/.
  • Runtime vs permanent: runtime changes vanish on reload or reboot. Add --permanent to persist a change, then activate it with --reload.

Step 1: Check firewalld Status – How to Configure Firewalld on Rocky

firewalld is installed and enabled by default on Rocky Linux 9. Verify it:

sudo systemctl enable --now firewalld
sudo firewall-cmd --state
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-all

The last command is your best friend: it prints the active zone, its interfaces, allowed services, ports and rich rules in one view.

Step 2: Allow Services and Ports – How to Configure Firewalld on Rocky

Allow the services your server actually provides, permanently:

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

Removing is symmetrical: replace --add- with --remove-. Close anything you do not use — for example, if you administer the server only through a hosting panel, you can remove the cockpit service that some images enable.

Firewall zones when you configure firewalld on Rocky Linux 9

Step 3: Work with Zones

If your server has two interfaces — one facing the internet and one on a private LAN — assign them to different zones:

sudo firewall-cmd --permanent --zone=public --change-interface=eth0
sudo firewall-cmd --permanent --zone=internal --change-interface=eth1
sudo firewall-cmd --permanent --zone=internal --add-service=samba
sudo firewall-cmd --reload

Now file sharing is available on the LAN but never exposed publicly. You can also create a custom zone with --new-zone when the built-ins do not fit.

Step 4: Write Rich Rules

Rich rules give you fine-grained control, for example allowing SSH only from your office IP:

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" service name="ssh" accept'
sudo firewall-cmd --permanent --remove-service=ssh
sudo firewall-cmd --reload

Rich rules can also log and drop traffic, rate-limit connections, or forward ports:

sudo firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080

The official firewalld documentation linked from docs.rockylinux.org describes the full rich-rule language.

Step 5: Define a Custom Service

For applications with several ports, a custom service file is cleaner than repeated --add-port calls. Create /etc/firewalld/services/myapp.xml:

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>MyApp</short>
  <port protocol="tcp" port="9000-9002"/>
</service>

Reload and use it like a built-in service:

sudo firewall-cmd --reload
sudo firewall-cmd --permanent --add-service=myapp

Emergency Tools: Panic Mode and Lockdown

If the server is under active attack, sudo firewall-cmd --panic-on drops all traffic instantly; --panic-off restores normal operation. Lockdown mode (--lockdown-on) prevents other local applications from modifying the firewall.

Troubleshooting

  • “I opened the port but it still does not work”: the change was runtime-only and got lost in a reload, or the service is not actually listening. Cross-check with ss -tlnp and firewall-cmd --list-all.
  • Rules exist twice or not at all: you mixed runtime and permanent config. Run firewall-cmd --runtime-to-permanent to save the live set, or reload to reset runtime from permanent.
  • Docker containers unreachable: Docker manages its own chains; see our guide to install Docker on Rocky Linux 9 for the firewall notes.

Step 6: Inspect the Real Ruleset (nftables Backend)

On Rocky Linux 9, firewalld programs the kernel through nftables. When behaviour surprises you, look at the generated ruleset directly:

sudo nft list ruleset | head -n 80
sudo firewall-cmd --get-policies
sudo firewall-cmd --info-zone=public

The --info-zone output is especially useful during audits: it lists the zone’s services, ports, protocols, forward ports and rich rules on one screen, including settings inherited from the zone’s XML definition. Firewalld also supports policies that control traffic flowing between zones — for example from the host to containers — which is how modern setups regulate forwarded traffic without raw iptables commands.

Step 7: Make Auditing a Habit

Treat the firewall like code: after every change, save the output of firewall-cmd --list-all together with your change ticket or commit message. Once a month, compare the live ruleset with what you expect to find. Stale openings — a test port from six months ago, a service from a removed application — are one of the most common findings in security audits, and they are trivially preventable when you review the firewall as part of routine maintenance.

Conclusion

You can now configure firewalld on Rocky Linux 9 confidently: inspect zones, allow services and ports permanently, restrict access with rich rules and recover from mistakes. Combined with the SSH hardening in our Rocky Linux 9 server setup guide, your server’s attack surface stays small and predictable.

You may also like

KbLinux

Typically replies within a day

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