Mastering firewalld on Fedora: From Zone Management to Rich Rules Pro Tips

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

Why firewalld is the Top Choice Over Raw iptables?

If you’ve ever “broken a sweat” managing old-school Linux servers, iptables is likely a name that haunts you. Managing iptables is like manually laying every single brick to build a fortress wall. One wrong command, and you could instantly lock yourself out of your own server.

On Fedora, firewalld acts as an intelligent management layer (frontend). It doesn’t completely replace iptables or nftables but makes interacting with them much easier. Its biggest advantage is the ability to update rules without interrupting existing connections—crucial for systems running continuous web or database services.

Installation and Activation in 30 Seconds

While Fedora Server usually comes with firewalld pre-installed, Minimal installations might lack it. You can quickly install it with the following command:

sudo dnf install firewalld -y
sudo systemctl enable --now firewalld

To make sure everything is ready, check the status:

sudo firewall-cmd --state

If you see running, congratulations—you’re ready to start building your server’s defense perimeter.

Zone Management: A Security Partitioning Mindset

Never leave everything in the default public zone. This is a mistake made by 80% of beginners. Think of Zones like security layers in a bank: anyone can enter the lobby, but the vault is off-limits.

In practice, I usually categorize them as follows:

  • public: Only open ports 80/443 for web users.
  • internal: For connections between Web Servers and Database Servers.
  • drop: A “black hole” for all unknown packets, extremely effective against automated port scanning tools.

To move a network interface (e.g., eth0) to a more secure zone:

sudo firewall-cmd --zone=internal --change-interface=eth0 --permanent
sudo firewall-cmd --reload

Using Services: Moving Beyond Manual Configuration

Remembering whether port 8080 or 9000 belongs to a specific service is a waste of time. Firewalld allows you to call services by name, making commands more readable and easier to manage.

For example, to permanently open the port for HTTPS:

sudo firewall-cmd --zone=public --add-service=https --permanent
sudo firewall-cmd --reload

Pro Tip: If you’ve just configured a series of temporary rules and they’re working correctly, use the command sudo firewall-cmd --runtime-to-permanent to save them all without re-typing each one with the --permanent flag.

Rich Rules: Solutions for Complex Scenarios

When basic rules are no longer enough, Rich Rules come into play. This is the most powerful tool for handling complex requirements in Production environments.

1. Restricting SSH Access to Specific IPs

To stop Brute-force attacks, I only allow a static IP from the office (e.g., 1.2.3.4) to access port 22:

sudo firewall-cmd --permanent --add-rich-rule='
  rule family="ipv4" 
  source address="1.2.3.4" 
  port protocol="tcp" port="22" accept'

2. Blocking Malicious IPs Instantly

If system logs show an IP 203.0.113.5 constantly sending junk requests, use the following command to “show them the door” without sending a response (reject):

sudo firewall-cmd --permanent --add-rich-rule='
  rule family="ipv4" 
  source address="203.0.113.5" reject'

3. Preventing Spam with Rate Limiting

You can limit the number of new connections to a service. For example, allowing a maximum of 3 SSH connections per minute to prevent resource exhaustion:

sudo firewall-cmd --permanent --add-rich-rule='
  rule service name="ssh" 
  limit value="3/m" accept'

Hard-Won Lessons for Remote Configuration

After setting everything up, always double-check with sudo firewall-cmd --list-all. However, the biggest risk is locking yourself out of the server while configuring SSH over the network.

Before making any “dangerous” changes, run this timer command:

sleep 300 && sudo systemctl stop firewalld

The logic is simple: If you lose connection, just wait 5 minutes. Firewalld will automatically stop, and you can log back in to fix the mistake. If everything is fine, press Ctrl+C to cancel the sleep command.

Conclusion

Mastering firewalld on Fedora isn’t difficult once you understand Zones and Rich Rules. Combining security partitioning with granular control makes your server resilient against common attacks. Start with the simplest rules and always keep your configuration files clean.

Share: