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, anddrop. Any zone created dynamically by an administrator (e.g., viafirewall-cmd --new-zone=customzone --permanent) is classified as a custom non-standard zone. - Gotchas: Confusing
drop(silently discards packets without ICMP error response) withblock(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
nftablesin kernel space as the underlying packet-filtering subsystem (replacing legacyiptables).firewalldacts as a high-level user-space management daemon that translates rules intonftablesrulesets. - Gotchas: Attempting to manipulate
iptablesdirectly; modern RHEL systems usenftablesas 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
nftablessyntax; manual XML file editing in/etc/firewalld/can be prone to syntax errors if modified outside offirewall-cmd. -
Why: Firewalld’s D-Bus interface permits services and utilities to request firewall adjustments dynamically without interrupting overall firewall operations.
-
Gotchas: Restarting
nftables.servicemanually whenfirewalldis 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-configprovides 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-configis 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
--permanentflag writes rule definitions to/etc/firewalld/zones/. Executingfirewall-cmd --reloadcompiles permanent configuration files into active kernel memory. - Gotchas: Executing
firewall-cmd --add-port=8080/tcpwithout--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
trustedzone allows all inbound and outbound network traffic without packet filtering or inspection. - Gotchas: Assigning public internet interfaces to the
trustedzone, 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
--permanentoption modifies XML files stored on disk in/etc/firewalld/. It does not update active runtime firewall rules in memory untilfirewall-cmd --reloadis executed (or unless--runtime-to-permanentis used after a runtime modification). - Gotchas: Adding a rule with
--permanentduring an exam and forgetting to runfirewall-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) withfirewall-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-permanentwhen 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-configandfirewall-cmdrely on D-Bus communication with the backgroundfirewalld.servicedaemon. If the service is inactive, configuration clients cannot read or modify settings. - Gotchas: Attempting to execute
firewall-cmdcommands whilefirewalldis masked or disabled results in aFirewalld is not runningerror. - 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-portrequires explicit protocol specification (/tcpor/udp). Specifying53/udppermits 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
greporlessto 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-serviceremoves the named service entry from the persistent zone XML file, and--reloadapplies the updated ruleset to runtime memory. - Gotchas: Removing a service only in runtime (
--remove-service) without--permanentcauses 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:
--reloadre-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 firewalldinstead offirewall-cmd --reload. While both apply configuration changes,systemctl restartdrops 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-alldisplays active services, ports, and interface bindings configured for the current default zone in runtime memory. - Gotchas: Inspecting
/etc/firewalld/zones/public.xmldirectly; 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-interfacebinds network interfaceeth1to theinternalzone, applying that zone’s firewall rules to all traffic entering viaeth1. - Gotchas: Binding an interface to multiple zones simultaneously. An interface can belong to only one zone at a time; use
--change-interfaceif 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
publicout 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-sourceroutes 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-servicethat 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 --reloadafter adding--permanentflags. -
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)