Network

The firewall-cmd command

Controls firewalld: opens and closes ports and services by zone.

Syntax

firewall-cmd [--state|--list-all|--add-port=|--reload]Try it in the terminal →

Most useful options

--stateSays whether firewalld is active: running, not running or failed
--reloadApplies the permanent configuration as runtime; runtime-only changes not saved are lost
--permanentApplies the change to the permanent configuration. It takes effect only after a reload or restart
--zone= <zona>Picks the zone. If omitted, the default zone is used
--add-port= <puerto/protocolo>Opens a port or a range, such as 80/tcp or 6000-6010/udp. Accepts --timeout
--list-allShows everything enabled in the zone: services, ports and more
--runtime-to-permanentSaves the active runtime configuration as permanent, overwriting it

Copy-ready examples

$ firewall-cmd --statechecks whether firewalld is active.

Example output

running
$ sudo firewall-cmd --add-port=8080/tcpopens port 8080 in runtime only: it is lost on a reload or a restart.

Example output

success
$ sudo firewall-cmd --permanent --add-port=8080/tcp && sudo firewall-cmd --reloadsaves it permanently and reloads so it takes effect.
$ firewall-cmd --zone=public --list-portslists the ports open in the public zone.

Example output

8080/tcp
$ sudo firewall-cmd --runtime-to-permanentsaves what you tested as the permanent configuration. It overwrites the previous one: check with --list-all first.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
bash: firewall-cmd: command not foundfirewalld is not installed. It is typical on Red Hat, Fedora and their derivatives; Debian and Ubuntu do not ship it by default.On Fedora or RHEL, install it with sudo dnf install firewalld. On Debian or Ubuntu, use ufw.
FirewallD is not runningThe service is stopped. Without --state, the tool waits a few seconds for D-Bus before giving this error.Start it with sudo systemctl start firewalld and check with firewall-cmd --state.
Authorization failed.polkit rejects the change because the account lacks privileges. The full message asks for a polkit agent or to run as superuser.Run the command again with sudo.

Typical mistakes

  • Without --permanent the change is runtime only: it is lost when firewalld reloads or restarts.
  • --reload discards runtime changes that are not in the permanent configuration. Save them first with --runtime-to-permanent if you want to keep them.
  • Closing the ssh service while you are connected over SSH locks you out. Allow it before changing the zone or the rules.

Differences from similar commands

  • ufw: is the usual firewall on Ubuntu. Its rules are not managed with firewall-cmd.
  • nft: writes nftables rules directly. firewall-cmd organizes them by zones and services.
  • iptables: is the classic chain-based rules tool. firewalld adds a zone layer on top.

Security

A wrong change can close your SSH access or leave a service open to the outside. Review with --list-all before reloading and keep a local console at hand.

FAQ

What is a zone?

A set of rules with a trust level. Each interface or source is assigned to a zone; anything without an assignment uses the default zone, which you can see with --get-default-zone.

How do I check what is open?

With --list-all for the default zone, or --zone=zone for another one. --list-ports shows only the ports.

Is it the same as ufw?

No. ufw is the usual firewall on Ubuntu; firewall-cmd belongs to firewalld, common on Red Hat, Fedora and derivatives.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course