Master firewalld: Essential Commands to Manage Linux Firewall Zones
This guide walks you through firewalld on CentOS 7, covering how to check status, start, restart, enable at boot, manage zones, configure ports, sources, and rich rules, and explains the impact of each command with practical examples for secure network administration.
Practice Environment
CentOS-7-x86_64-DVD-2009
Introduction
Firewalld is a simple, stateful, zone‑based firewall. Policies and zones organize firewall rules. The network is logically divided into zones, and traffic between zones can be managed via policies.
Check Firewall Status
# service firewalld statusor
# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)If the output shows Active: inactive (dead), the firewall is not running; Active: active (running) means it is enabled.
Start Firewall
# service firewalld startor
# systemctl start firewalldRestart Firewall
# service firewalld restartor
# systemctl restart firewalldEnable/Disable Firewall at Boot
# systemctl enable firewalld
# systemctl disable firewalldView Predefined Zones
# firewall-cmd --get-zones
block dmz drop external home internal public trusted workTo see details of each zone: # firewall-cmd --list-all-zones block : reject incoming traffic unless it is related to outgoing traffic.
dmz : reject incoming traffic unless related to outgoing; allow if the traffic is for ssh.
drop : same as block.
external : reject incoming traffic unless related; allow ssh.
home : reject incoming traffic unless related; allow ssh, mdns, ipp-client, amba-client, dhcpv6-client.
internal : equivalent to home.
public : reject incoming traffic unless related; allow ssh, dhcpv6-client.
trusted : allow all inbound and outbound packets.
work : reject incoming traffic unless related; allow ssh, ipp-client, dhcpv6-client.
Create Custom Zone
# firewall-cmd --permanent --new-zone=testing
success --permanentmust be included.
View Default Zone
# firewall-cmd --get-default-zone
publicView Interface‑Zone Association
# ip addr
... (output omitted) ...
# firewall-cmd --get-zone-of-interface=ens33
publicNote: one network interface can be bound to only one zone.
Change Default Zone
# firewall-cmd --set-default-zone=trusted
success
# firewall-cmd --get-default-zone
trusted
# firewall-cmd --set-default-zone=public
success
# firewall-cmd --get-default-zone
publicModify Interface Zone
Method 1 – remove then add:
# firewall-cmd --remove-interface=ens33 --zone=public
success
# firewall-cmd --add-interface=ens33 --zone=trusted
successMethod 2 – change directly:
# firewall-cmd --change-interface=ens33 --zone=public
successList Active Zones
# firewall-cmd --get-active-zones
public
interfaces: ens33Port Access Control
List Open Ports
# firewall-cmd [--permanent] [--zone=zone] --list-portsThe list shows ports added to the specified zone in the form portid[-portid]/protocol.
Add Open Port
# firewall-cmd [--permanent] [--zone=zone] --add-port=portid[-portid]/protocol [--timeout=timeval] --timeoutcannot be used together with --permanent.
Remove Open Port
# firewall-cmd [--permanent] [--zone=zone] --remove-port=portid[-portid]/protocolExamples
Persistently open TCP port 15672 in the public zone:
# firewall-cmd --permanent --add-port=15672/tcp
# firewall-cmd --reload
success
# firewall-cmd --list-ports
15672/tcpPersistently open a port range 1000‑2000:
# firewall-cmd --permanent --add-port=1000-2000/tcp
success
# firewall-cmd --reload
success
# firewall-cmd --list-ports
15672/tcp 1000-2000/tcpPersistently remove a port:
# firewall-cmd --permanent --remove-port=15672/tcp
success
# firewall-cmd --reload
success
# firewall-cmd --list-ports
1000-2000/tcpIP/Network Access Control
Add Source
# firewall-cmd [--permanent] [--zone=zone] --add-source=source[/mask]|MAC|ipset:ipsetBind an IP, network, MAC or ipset to a zone. If --zone is omitted, the default zone is used.
Remove Source
# firewall-cmd [--permanent] --remove-source=source[/mask]|MAC|ipset:ipsetExamples
Allow a single IP permanently in the public zone:
# firewall-cmd --permanent --add-source=192.168.50.182
success
# firewall-cmd --reload
successAllow an entire subnet permanently:
# firewall-cmd --permanent --add-source=192.168.50.0/24
success
# firewall-cmd --reload
successRemove a previously added source:
# firewall-cmd --permanent --remove-source=192.168.50.182
success
# firewall-cmd --reload
successRich Language Rules
List Rich Rules
# firewall-cmd [--permanent] [--zone=zone] --list-rich-rulesAdd Rich Rule
# firewall-cmd [--permanent] [--zone=zone] --add-rich-rule='rule' [--timeout=timeval]Remove Rich Rule
# firewall-cmd [--permanent] [--zone=zone] --remove-rich-rule='rule'Query Rich Rule
# firewall-cmd [--permanent] [--zone=zone] --query-rich-rule='rule'Examples
Allow IP 192.168.50.182 permanent access to TCP port 15672 in the public zone:
# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.50.182" port protocol="tcp" port="15672" accept'
# firewall-cmd --reloadRemove the above rule:
# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.50.182" port protocol="tcp" port="15672" accept'
# firewall-cmd --reloadBlock the IP permanently:
# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.50.182" reject'
# firewall-cmd --reloadRemove the block:
# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.50.182" reject'
# firewall-cmd --reloadList All Settings for a Zone
# firewall-cmd [--permanent] [--zone=zone] --list-allExample output for the public zone shows target, interfaces, sources, services, ports, protocols, masquerade, forward‑ports, source‑ports, icmp‑blocks, and rich rules.
Save Runtime Configuration Permanently
# firewall-cmd --runtime-to-permanentThis command writes the current runtime configuration to the permanent configuration files.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
