VOOZH about

URL: https://thenewstack.io/firewalld-an-easier-way-to-manage-linux-firewalls/

⇱ Firewalld: An Easier Way to Manage Linux Firewalls - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-12-23 06:00:46
Firewalld: An Easier Way to Manage Linux Firewalls
Security

Firewalld: An Easier Way to Manage Linux Firewalls

Tired of iptables? With firewalld, you can easily open ports, block IP addresses, manage zones, and even add a GUI for easier management.
Dec 23rd, 2023 6:00am by Jack Wallen
👁 Featued image for: Firewalld: An Easier Way to Manage Linux Firewalls
Feature Image by Gerd Altmann from Pixabay, penguin by M. Harris, Pixabay.

If you use either Rocky Linux or AlmaLinux as your server operating system of choice, you’ll find them as powerful as it is flexible. And thankfully, they are not nearly as complicated as they once were.

Take, for instance, the firewall. Back in the old days, working with the firewall required you get to know the highly complicated iptables utility.

Here’s a sample command for adding an iptables rule:

iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP

This adds a rule to the INPUT chain for incoming TCP traffic on port 22, and uses the recent module to mark the source IP address, updates the rule to drop packets if the rate limit exceeds 4 new connections within 60 seconds.

To be fair, iptables is capable of doing some very complicated things. But with that complication comes the challenge of writing rules that work. It takes a long time to master iptables and most new Linux admins are busy just getting up to speed with the basics of the operating system.

What Is Firewalld?

That’s why the far simpler firewalld is a better place to start. Firewalld is a firewall management tool that provides a dynamically managed firewall that is user-friendly and supports features like network zones. With firewalld, you can easily open ports, block IP addresses, manage zones, and even add a GUI for easier management (so long as you’ve installed Rocky Linux with a desktop environment).

Let’s dive in and take our first steps with this powerful firewall tool.

What You Need

To follow along, you’ll need a Linux distribution that uses firewalld (such as Red Hat Enterprise Linux, Rocky Linux, Alma Linux, CentOS Stream, or Fedora) and a user with sudo privileges. That’s it, let’s get to know this firewall system.

Enable the Firewall

Out of the box, you might find the firewall is disabled. Because firewalld runs as a service on your Linux distribution, you can enable it with the help of systemctl like so:

sudo systemctl enable --now firewalld

You can then verify the firewall is running with the command:

sudo systemctl status firewalld

It should be listed as active (running).

List Currently Active Rules

Next, we’re going to take a look at the currently active rules running in the firewall. This can be done with the command:

sudo firewall-cmd --list-all

Notice the command is not firewalld, but firewall-cmd. Firewalld is the daemon (service) and firewall-cmd is the command used to manage the rules.

The output of the above command will look something like this:

public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: cockpit dhcpv6-client dns freeipa-ldap freeipa-ldaps kerberos ntp
  ports: 2377/tcp 7946/tcp 7946/udp 4789/udp 10000/tcp
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Instead of listing both ports and services simultaneously, you could view them separately with the command:

sudo firewall-cmd --list-ports
sudo firewall-cmd --list-services

Adding a Service or Port through the Firewall

Let’s say you need to add HTTP (port 80) and SSH (port 22) through the firewall. Before we do that, we have to decide which zone we’ll work with, of which there are nine (drop, block, public, external, internal, dmz, work, home, and trusted). Of those nine, you’ll probably mostly work with these four:

  • public – public, untrusted networks
  • home – private, trusted networks
  • work – same as home, only used for business purposes
  • trusted – all connected machines are trusted

For our purposes, we’re going to focus on the public zone because that is generally associated with external connections (WAN). If you’re running a web server, you’ll probably want to allow public traffic through the firewall so it can reach the websites you are serving up.

To make sure you’re using the public zone, use the following command:

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

Verify the change with:

sudo firewall-cmd --get-active-zones

You should see something like this in the output:

public
  interfaces: enp0s3

To allow port 80 (HTTP) through, issue the command:

sudo firewall-cmd --zone=public --add-port=80/tcp --permanent

What that does is add the new rule but it doesn’t automatically activate it. For that, you must reload the firewall with the command:

sudo firewall-cmd --reload

Now, if you check the firewalld status, you’ll see HTTP listed. Let’s say you also need HTTPS added to the firewall. Instead of using the port number, we can do so via a service like so:

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

Again, reload the firewall with:

sudo firewall-cmd --reload

You can do the same thing with SSH (port 22), which can be added with either of the following commands:

sudo firewall-cmd --zone=public --add-port=22/tcp --permanent
sudo firewall-cmd --zone=public --add-service=ssh --permanent

Reload the firewall with:

sudo firewall-cmd --reload

Removing a Port or Service from the Firewall

In the same way, you can remove a service or port from the firewall, thereby blocking access to the server. Sticking with our examples, we can remove access via a service with a command like this:

sudo firewall-cmd --zone=public --remove-service=https --permanent

We can also remove access via a port like so:

sudo firewall-cmd --zone=public --remove-port=443/tcp --permanent

Notice we have to use a protocol (such as tcp) when adding or removing via port numbers, which isn’t required when adding or removing via service. And, remember, any time you modify the firewall, you have run the sudo firewall-cmd –reload command before the changes take effect.

And there you have it, your first steps with the firewalld system. Thankfully, you don’t have to worry about working with the iptables command, which is far more complicated. To learn more about firewalld, check out the official documentation.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
Red Hat is a sponsor of The New Stack.
TNS owner Insight Partners is an investor in: Alma, Enable.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.