$linuxjunkies
>

firewall-cmd(1)

Control the firewalld daemon and manage firewall rules dynamically without restarting the service.

UbuntuDebianFedoraArch

Synopsis

firewall-cmd [OPTIONS] [ZONE]

Description

firewall-cmd is the command-line interface to firewalld, the dynamic firewall manager for Linux systems. It allows you to manage firewall rules, zones, and services in real-time without requiring a restart of the firewall daemon.

Changes made with firewall-cmd are temporary by default. Use the --permanent flag to make changes persistent across reboots. After adding permanent rules, reload the firewall with --reload to apply them immediately.

firewalld uses zones to define trust levels for network connections, and supports both predefined services and custom rules for granular control over inbound and outbound traffic.

Common options

FlagWhat it does
--permanentMake the rule persistent; without this flag, changes are temporary until reboot
--reloadReload firewall rules from disk, applying all permanent changes
--add-service=SERVICEAllow traffic for a named service (e.g., http, ssh, https)
--remove-service=SERVICERemove a previously allowed service
--add-port=PORT/PROTOCOLAllow traffic on a specific port (e.g., 8080/tcp)
--remove-port=PORT/PROTOCOLDeny traffic on a specific port
--list-servicesList all available predefined services
--list-allShow all rules, services, and settings for the active zone
--get-active-zonesDisplay zones currently bound to network interfaces
--set-default-zone=ZONEChange the default zone for unassigned interfaces
--add-source=CIDR --zone=ZONEAllow all traffic from a source IP address or subnet
--stateCheck if firewalld is running

Examples

Check if the firewall daemon is currently running

sudo firewall-cmd --state

Display which zones are currently active and their assigned interfaces

sudo firewall-cmd --get-active-zones

Show all firewall rules and services for the default zone

sudo firewall-cmd --list-all

Temporarily allow HTTP and HTTPS traffic (until reboot)

sudo firewall-cmd --add-service=http --add-service=https

Permanently allow SSH, then reload to apply the change immediately

sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload

Temporarily allow TCP traffic on port 8080 in the public zone

sudo firewall-cmd --add-port=8080/tcp --zone=public

Permanently trust all traffic from the 192.168.1.0/24 subnet

sudo firewall-cmd --permanent --add-source=192.168.1.0/24 --zone=trusted

Display all available predefined services that can be quickly enabled

sudo firewall-cmd --list-services

Related commands