Domain 10Security & FirewallsCORE

Managing Firewall

Comprehensive guide to RHEL firewalld configuration, covering zones, runtime vs. permanent rules, service additions, port forwarding, and reboot persistence.

Domain: Manage security•Updated: 2026-08-30
#Firewall#Firewalld#Firewall-cmd#Security#Ports#Services#RHCSA#RHEL

Managing Firewall

Theory Questions

1. Identify standard and non-standard Firewalld zones.

  • Command(s):
firewall-cmd --get-zones
  • Why: Firewalld ships with nine standard predefined zones representing different levels of trust: trusted, home, internal, work, dmz, external, public, block, and drop. Any zone created dynamically by an administrator (e.g., via firewall-cmd --new-zone=customzone --permanent) is classified as a custom non-standard zone.
  • Gotchas: Confusing drop (silently discards packets without ICMP error response) with block (rejects connections with ICMP destination-unreachable messages).
  • Verify:
firewall-cmd --get-zones

2. Identify the firewalling service implemented in the Linux kernel.

  • Command(s):
nft list ruleset
  • Why: Modern RHEL distributions use nftables in kernel space as the underlying packet-filtering subsystem (replacing legacy iptables). firewalld acts as a high-level user-space management daemon that translates rules into nftables rulesets.
  • Gotchas: Attempting to manipulate iptables directly; modern RHEL systems use nftables as the backend engine.
  • Verify:
systemctl status firewalld

3. Evaluate advantages and disadvantages of Firewalld.

  • Command(s):
firewall-cmd --state
  • Evaluation:

  • Advantages: Supports dynamic configuration changes without dropping active state tables or established network connections; offers abstract zone-based security models and pre-defined XML service definitions.

  • Disadvantages: Adds an administrative abstraction layer over native nftables syntax; manual XML file editing in /etc/firewalld/ can be prone to syntax errors if modified outside of firewall-cmd.

  • Why: Firewalld’s D-Bus interface permits services and utilities to request firewall adjustments dynamically without interrupting overall firewall operations.

  • Gotchas: Restarting nftables.service manually when firewalld is active can flush dynamically generated Firewalld chains.

  • Verify:

firewall-cmd --state

4. List all available Firewalld services.

  • Command(s):
firewall-cmd --get-services
  • Why: Pre-defined service definitions map application names (e.g., http, ssh, dns) to their associated ports and protocols without requiring manual port number definitions.
  • Gotchas: Assuming custom application ports are included in default service definitions; if a non-standard port is used (e.g., HTTP on port 8080), you must add the port explicitly or create a custom service XML.
  • Verify:
firewall-cmd --get-services | grep -o "http"

5. Identify the GUI tool for managing Firewalld configurations.

  • Command(s):
firewall-config
  • Why: firewall-config provides a graphical interface (GTK) to inspect and adjust runtime and permanent firewalld settings. Cockpit (cockpit-ws) also provides web-based graphical firewall controls.
  • Gotchas: firewall-config is not installed on minimal server installations by default.
  • Verify:
rpm -q firewall-config

6. Add a port persistently to the current Firewalld configuration.

  • Command(s):
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
  • Why: The --permanent flag writes rule definitions to /etc/firewalld/zones/. Executing firewall-cmd --reload compiles permanent configuration files into active kernel memory.
  • Gotchas: Executing firewall-cmd --add-port=8080/tcp without --permanent. Runtime changes apply immediately but are discarded when the server reboots or firewalld reloads.
  • Verify:
firewall-cmd --list-ports

7. Choose the appropriate zone for a fully trusted network.

  • Command(s):
firewall-cmd --set-default-zone=trusted
  • Why: The trusted zone allows all inbound and outbound network traffic without packet filtering or inspection.
  • Gotchas: Assigning public internet interfaces to the trusted zone, exposing all system services to remote network traffic.
  • Verify:
firewall-cmd --get-default-zone

8. Understand the behavior of the --permanent option with firewall-cmd.

  • Command(s):
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
  • Why: The --permanent option modifies XML files stored on disk in /etc/firewalld/. It does not update active runtime firewall rules in memory until firewall-cmd --reload is executed (or unless --runtime-to-permanent is used after a runtime modification).
  • Gotchas: Adding a rule with --permanent during an exam and forgetting to run firewall-cmd --reload, causing live test checks to fail immediately.
  • Verify:
firewall-cmd --list-services            # Shows active runtime rules
firewall-cmd --permanent --list-services # Shows persistent on-disk rules

9. Get an overview of all firewall configurations for all zones.

  • Command(s):
firewall-cmd --list-all-zones
  • Why: Displays active services, ports, protocols, interface bindings, and source addresses configured across every predefined and custom zone on the system.
  • Gotchas: Confusing firewall-cmd --list-all (which outputs only the active/default zone) with firewall-cmd --list-all-zones (which lists every zone).
  • Verify:
firewall-cmd --list-all-zones | head -n 30

10. Write the current runtime configuration to the permanent configuration.

  • Command(s):
firewall-cmd --runtime-to-permanent
  • Why: Captures all dynamic, non-persistent rules currently active in memory and saves them into the persistent XML zone files under /etc/firewalld/zones/.
  • Gotchas: Using --runtime-to-permanent when testing unverified rules; invalid runtime rules will become persistent across reboots.
  • Verify:
firewall-cmd --permanent --list-all

11. Ensure the correct service is running before using firewall-config.

  • Command(s):
systemctl status firewalld
  • Why: firewall-config and firewall-cmd rely on D-Bus communication with the background firewalld.service daemon. If the service is inactive, configuration clients cannot read or modify settings.
  • Gotchas: Attempting to execute firewall-cmd commands while firewalld is masked or disabled results in a Firewalld is not running error.
  • Verify:
systemctl is-active firewalld

12. Add a UDP port to the firewall configuration in the default zone.

  • Command(s):
firewall-cmd --permanent --add-port=53/udp
firewall-cmd --reload
  • Why: --add-port requires explicit protocol specification (/tcp or /udp). Specifying 53/udp permits DNS UDP traffic through the default zone.
  • Gotchas: Omitting /udp (e.g., --add-port=53), which returns an invalid port specification error.
  • Verify:
firewall-cmd --list-ports

13. List all firewall configurations in all zones.

  • Command(s):
firewall-cmd --list-all-zones
  • Why: Displays comprehensive configuration parameters for all available zones.
  • Gotchas: Parsing large output screens manually; pipe through grep or less to locate specific interfaces or services.
  • Verify:
firewall-cmd --list-all-zones

14. Remove a service (e.g., vnc-server) from the current firewall configuration.

  • Command(s):
firewall-cmd --permanent --remove-service=vnc-server
firewall-cmd --reload
  • Why: --remove-service removes the named service entry from the persistent zone XML file, and --reload applies the updated ruleset to runtime memory.
  • Gotchas: Removing a service only in runtime (--remove-service) without --permanent causes the service entry to return upon the next firewalld reload or system reboot.
  • Verify:
firewall-cmd --list-services

15. Activate a new configuration added with --permanent.

  • Command(s):
firewall-cmd --reload
  • Why: --reload re-reads on-disk XML files from /etc/firewalld/ and applies the updated rules to the runtime kernel state table without interrupting active connections.
  • Gotchas: Running systemctl restart firewalld instead of firewall-cmd --reload. While both apply configuration changes, systemctl restart drops active state tracking sessions.
  • Verify:
firewall-cmd --list-all

16. Verify that a new configuration is active in the current zone.

  • Command(s):
firewall-cmd --list-all
  • Why: firewall-cmd --list-all displays active services, ports, and interface bindings configured for the current default zone in runtime memory.
  • Gotchas: Inspecting /etc/firewalld/zones/public.xml directly; on-disk XML changes do not confirm that the rule is active in kernel memory unless reloaded.
  • Verify:
firewall-cmd --list-all

17. Add a specific network interface to a zone.

  • Command(s):
firewall-cmd --permanent --zone=internal --add-interface=eth1
firewall-cmd --reload
  • Why: --add-interface binds network interface eth1 to the internal zone, applying that zone’s firewall rules to all traffic entering via eth1.
  • Gotchas: Binding an interface to multiple zones simultaneously. An interface can belong to only one zone at a time; use --change-interface if moving between zones.
  • Verify:
firewall-cmd --zone=internal --list-interfaces

18. Determine which zone a new interface is added to when no zone is specified.

  • Command(s):
firewall-cmd --get-default-zone
  • Why: Unassigned network interfaces managed by NetworkManager automatically inherit the system default zone (configured as public out of the box).
  • Gotchas: Assuming unassigned interfaces default to trusted.
  • Verify:
firewall-cmd --get-active-zones

19. Add a source IP address range to the default zone.

  • Command(s):
firewall-cmd --permanent --add-source=192.168.1.0/24
firewall-cmd --reload
  • Why: Adding a CIDR range via --add-source routes incoming packets from matching source IPs into the designated zone regardless of interface binding.
  • Gotchas: Overlapping source IP rules across conflicting zones, which can result in unexpected rule evaluation order.
  • Verify:
firewall-cmd --list-sources

20. List all services currently available in Firewalld.

  • Command(s):
firewall-cmd --get-services
  • Why: Displays all pre-configured service names defined under /usr/lib/firewalld/services/ and /etc/firewalld/services/.
  • Gotchas: Typing custom service names into --add-service that are not listed in --get-services.
  • Verify:
firewall-cmd --get-services

Lab Tasks

Firewall Practice

Task: Create a firewall configuration that allows access to web (HTTP/HTTPS), FTP, and SSH services. Make the configuration persistent so it is activated after a server restart.

  • Command(s):
# 1. Ensure firewalld service is enabled and running:
systemctl enable --now firewalld

# 2. Add required services persistently to the default zone:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-service=ftp
firewall-cmd --permanent --add-service=ssh

# 3. Reload firewalld to apply persistent rules to runtime:
firewall-cmd --reload
  • Why:

  • systemctl enable --now firewalld: Starts the service immediately and enables it across system reboots.

  • firewall-cmd --permanent: Writes rules to persistent XML files in /etc/firewalld/zones/.

  • firewall-cmd --reload: Loads persistent rules into active memory without disconnecting existing sessions.

  • Gotchas:

  • Forgetting to execute firewall-cmd --reload after adding --permanent flags.

  • Adding rules only to runtime (without --permanent), causing settings to be lost upon system reboot.

  • Forgetting that FTP requires helper modules or passive port ranges if operating behind NAT.

  • Verify Runtime Rules:

firewall-cmd --list-services

(Output must include: http https ftp ssh)

  • Verify On-Disk Persistence:
firewall-cmd --permanent --list-services

(Confirms services are written into the persistent configuration file)

  • Reboot Verification:
reboot

# Post-reboot check:
systemctl is-active firewalld
firewall-cmd --list-services

(Confirms firewalld is active and all requested services remain accessible across reboots)