Firewall front ends: ufw and firewalld

Intermediate · 15 min

Manage a host firewall with ufw or firewalld: default policies, zones, services, runtime versus permanent, and the nftables rules underneath.

Before thisPacket filtering with nftablesHardening SSH on a serverPersistent network configuration

The Lazy SysAdmin · 15 min

Firewall front ends: ufw and firewalld

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by The Lazy SysAdminReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • ufw and firewalld do not filter packets themselves. They turn short commands into netfilter rules, which on current systems means nftables, and keep those rules across reboots.
  • ufw, the Ubuntu default, is a rule list with default policies: `ufw default deny incoming`, `ufw allow OpenSSH`, `ufw enable`. `ufw limit` denies an address that opens 6 or more connections in 30 seconds.
  • firewalld, the RHEL-family default, sorts traffic into zones by interface or source address. Each zone allows a set of services and ports. The default zone is `public`.
  • firewalld keeps runtime and permanent configuration apart. A change without `--permanent` is lost on reload. A `--permanent` change is not live until `firewall-cmd --reload`.
  • Use one front end per machine, never alongside hand-written nftables rules for the same hooks. `nft list ruleset` shows what the kernel actually enforces.

Why a front end at all

The nftables lesson built a default-deny ruleset by hand. That works well for one server whose ruleset lives in Git. It works less well when a package wants to open its own port, when a laptop moves between a trusted office and a café, or when a team just needs “allow HTTPS” without learning the hook priorities.

ufw and firewalld are front ends. Each keeps its own simpler model of the firewall, turns it into kernel rules, and reloads those rules at boot. Think of a building’s access-control software: the guard picks “contractors may enter floor 3 until 6 p.m.”, and the software programs every door reader. The doors still do the work. The software just keeps the instructions straight.

Ubuntu ships ufw and leaves it inactive until you enable it. The RHEL family ships firewalld, enabled by default.

ufw: a list with defaults

ufw models the firewall as default policies plus an ordered list of rules. From the ufw manual (0.36.2, Ubuntu 24.04):

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH            # an application profile
sudo ufw limit ssh/tcp            # allow, but rate-limit
sudo ufw allow from 192.0.2.0/24 to any port 5432 proto tcp
sudo ufw enable
sudo ufw status verbose

OpenSSH is an application profile, one of the files packages drop into /etc/ufw/applications.d. limit is ufw’s built-in brute-force brake: the manual says an address that tries to open 6 or more connections within 30 seconds is denied. ufw enable prompts when run over SSH, because a default-deny policy with no SSH rule cuts off your session. That prompt is there for a reason, so add the SSH rule first.

ufw status shows only the rules you added. The manual points to ufw show raw for the full state, because ufw also loads its own boilerplate rules from files in /etc/ufw.

firewalld: zones and services

firewalld starts from a different idea. Its concepts page says the network “is logically divided into zones”, that traffic “ingresses one and only one zone”, and that “a zone defines a level of trust”. A zone is a bundle of what is allowed, and traffic is assigned to a zone by the interface it arrived on or by its source address. Zones come predefined, such as drop, block, public, internal and trusted. firewalld.conf sets the default zone to public, so an interface nobody assigned lands there.

Inside a zone you allow services, named bundles of ports such as ssh, http or cockpit, or raw ports:

sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --list-all
sudo firewall-cmd --zone=public --add-service=https --permanent
sudo firewall-cmd --zone=internal --add-source=10.0.0.0/8 --permanent
sudo firewall-cmd --reload

Runtime versus permanent

This is the firewalld behaviour that surprises people. The concepts page: “Firewalld maintains separate runtime and permanent configurations”, and “the runtime configuration does not persist after a firewalld reload or restart”. So:

  • --add-service=https alone is live now and gone after a reload.
  • --add-service=https --permanent is saved, but not live until --reload.
  • --runtime-to-permanent saves whatever is live right now.

The split is a safety feature. Try a change at runtime, and if it locks you out, a restart of firewalld or of the machine brings back the saved rules. Once it works, make it permanent.

What ends up in the kernel

Both tools produce netfilter rules. firewalld.conf lists nftables as the default FirewallBackend and calls the iptables backend deprecated. firewalld creates its own nftables tables, which you see with sudo nft list ruleset. ufw is built on iptables commands, and on current Ubuntu iptables is the nftables-backed iptables-nft. So ufw’s chains also appear in nft list ruleset, with names starting ufw-.

The rule that follows: one front end per machine, and no hand-edited nftables rules on the same hooks. Two tools that each think they own the firewall will fight, and the loser’s rules vanish on the next reload. Container engines are the usual extra player. Docker, for example, writes its own NAT rules for published ports, so check nft list ruleset before trusting that ufw’s view is the whole story.

None of these commands were run. There is no Linux machine here, and they are written from the ufw manual and firewalld documentation, checked 2026-11-28.

About the video

The embed is all of The Lazy SysAdmin’s “Firewalld Tutorial for Beginners | Complete Linux Firewall Guide (RHEL 10, Rocky, AlmaLinux)”, November 2026, 15 minutes. Its chapters cover zones, services versus ports, opening and closing ports, runtime versus permanent, binding interfaces to zones, rich rules and a web server setup, on RHEL 10. It is firewalld only. For ufw, the Learn Linux TV guide in deeper (July 2026, 29 minutes) has chapters on default policies, SSH from specific addresses, rate limiting and logging. Neither video, going by its chapters, shows the nftables rules underneath, which is this lesson’s own part. I judged both from titles, chapters and descriptions, and English from their English caption tracks.

Where this fits

Firewalls decide which packets reach a service. The next layer decides what a service may do once it is running, even as root: SELinux.

Check yourself

  1. 01You ran `firewall-cmd --add-service=https` and it worked, but after a reboot HTTPS is blocked again. Why?

    Without `--permanent` the change went into the runtime configuration only, which is discarded on reload or restart. Repeat it with `--permanent` and reload, or save the runtime state with `firewall-cmd --runtime-to-permanent`.

  2. 02On firewalld, what decides which zone's rules apply to an incoming packet?

    The zone the traffic is bound to, by its source address or by the interface it arrived on. Anything not bound elsewhere falls into the default zone, `public` out of the box.

  3. 03Before running `ufw enable` on a remote server with a default-deny policy, what must you do?

    Add a rule allowing SSH, such as `ufw allow OpenSSH` or `ufw limit ssh/tcp`. ufw warns when it is enabled over SSH because it can cut off your own session.

  4. 04Where would you look to see the rules ufw or firewalld actually created?

    `sudo nft list ruleset`, which shows the kernel's real rules whichever tool wrote them. `ufw show raw` and `firewall-cmd --list-all` show each tool's own view.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark