firewalld
¶
Firewalld is the firewall that is used on RedHat-based distributions (i.e., Rocky Linux, RHEL).
Firewalld utilizes iptables
.
Configuration for services and zones are stored in XML files in /usr/lib/firewalld/
.
Controlling Firewalld¶
The command line tool for controlling firewalld
is firewall-cmd
.
-
Check if the firewalld daemon is running, and start/enable it:
-
Check what ports are exposed in
firewalld
-
Check what services are allowed through
firewalld
-
Check both exposed services and ports:
-
List the firewall's "zones", and see if they have anything assigned to them:
-
List active zones nad what network interface they're attached to:
-
Check the configuration files for a specific zone:
-
Expose a port in
firewalld
:# make temp changes firewall-cmd --add-port=8080/tcp firewall-cmd --add-port=8080/udp # make changes persist firewall-cmd --permanent --add-port=8080/tcp firewall-cmd --permanent --add-port=8080/udp # reload so changes take effect firewall-cmd --reload
- This will add the ports, but the changes will not be persistent.
- Use the
--permanent
flag to make changes persist.
- Use the
- Each rule must specify what kind of packets are allowed through the port (
tcp
/udp
).
- This will add the ports, but the changes will not be persistent.
-
Expose several ports in
firewalld
: -
Expose a service in
This must be a "supported service."firewalld
:
To get a list of 'supported' services to use with--add-service
:
-
Add a 'masquerade' rule:
- Adds a
MASQUERADE
rule toiptables
(used by firewalld). - Ensures that packets exiting the node can use the node's external IP.
- Masquerade verification:
- Adds a
Working with Ports¶
Adding/Exposing Ports¶
To expose a port in firewalld
, use the --add-port
option:
# make temp changes during runtime
firewall-cmd --add-port=8080/tcp
firewall-cmd --add-port=8080/udp
Any changes without
--permanent
will only be part of the runtime configuration.
# make permanent changes
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=8080/udp
# reload so permanent changes take effect
firewall-cmd --reload
-
Use the
--permanent
flag to make changes persist.- When using
--permanent
, you must reload or restartfirewalld
for changes to take effect.
- When using
-
To make changes in both the runtime config and permanent config without reloading, use the same call with and without the
--permanent
flag. -
Each rule must specify what kind of packets are allowed through the port (
tcp
/udp
).
If you want to add a port only for a specific zone, you can specify the --zone
:
firewall-cmd --permanent --zone=public --add-port=8080/tcp
firewall-cmd --permanent --zone=public --add-port=8080/udp
firewall-cmd --reload
Removing Ports¶
This works in the same way as adding ports, but use the --remove-port
option
instead.
Again, use --permanent
and --reload
to make permanent changes.
firewall-cmd --permanent --remove-port=8080/tcp
firewall-cmd --permanent --remove-port=8080/udp
firewall-cmd --reload
Working with Services¶
Checking Service Rules for Firewalld¶
Configuration for services and zones are stored in XML files in /usr/lib/firewalld/
.
You can view how firewalld
stores rules in XML, and modify them if need be.
To check the configuration for a service (node_exporter
):