Chapter 40. Using and configuring firewalld
A
firewall
is a way to protect machines from any unwanted traffic from outside. It enables users to control incoming network traffic on host machines by defining a set of
firewall rules
. These rules are used to sort the incoming traffic and either block it or allow through.
firewalld
is a firewall service daemon that provides a dynamic customizable host-based firewall with a D-Bus interface. Being dynamic, it enables creating, changing, and deleting the rules without the necessity to restart the firewall daemon each time the rules are changed.
firewalld
uses the concepts of zones and services, that simplify the traffic management. Zones are predefined sets of rules. Network interfaces and sources can be assigned to a zone. The traffic allowed depends on the network your computer is connected to and the security level this network is assigned. Firewall services are predefined rules that cover all necessary settings to allow incoming traffic for a specific service and they apply within a zone.
Services use one or more ports or addresses for network communication. Firewalls filter communication based on ports. To allow network traffic for a service, its ports must be open.
firewalld
blocks all traffic on ports that are not explicitly set as open. Some zones, such as trusted, allow all traffic by default.
Note that
firewalld
with
nftables
backend does not support passing custom
nftables
rules to
firewalld
, using the
--direct
option.
40.1. When to use firewalld, nftables, or iptables
The following is a brief overview in which scenario you should use one of the following utilities:
firewalld
: Use the
firewalld
utility for simple firewall use cases. The utility is easy to use and covers the typical use cases for these scenarios.
nftables
: Use the
nftables
utility to set up complex and performance-critical firewalls, such as for a whole network.
iptables
: The
iptables
utility on Red Hat Enterprise Linux uses the
nf_tables
kernel API instead of the
legacy
back end. The
nf_tables
API provides backward compatibility so that scripts that use
iptables
commands still work on Red Hat Enterprise Linux. For new firewall scripts, Red Hat recommends to use
nftables
.
To prevent the different firewall-related services (
firewalld
,
nftables
, or
iptables
) from influencing each other, run only one of them on a RHEL host, and disable the other services.
40.2. Firewall zones
You can use the
firewalld
utility to separate networks into different zones according to the level of trust that you have with the interfaces and traffic within that network. A connection can only be part of one zone, but you can use that zone for many network connections.
firewalld
follows strict principles in regards to zones:
Traffic ingresses only one zone.
Traffic egresses only one zone.
A zone defines a level of trust.
Intrazone traffic (within the same zone) is allowed by default.
Interzone traffic (from zone to zone) is denied by default.
Principles 4 and 5 are a consequence of principle 3.
Principle 4 is configurable through the zone option
--remove-forward
. Principle 5 is configurable by adding new policies.
NetworkManager
notifies
firewalld
of the zone of an interface. You can assign zones to interfaces with the following utilities:
NetworkManager
firewall-config
utility
firewall-cmd
utility
The RHEL web console
The RHEL web console,
firewall-config
, and
firewall-cmd
can only edit the appropriate
NetworkManager
configuration files. If you change the zone of the interface using the web console,
firewall-cmd
, or
firewall-config
, the request is forwarded to
NetworkManager
and is not handled by
firewalld
.
The
/usr/lib/firewalld/zones/
directory stores the predefined zones, and you can instantly apply them to any available network interface. These files are copied to the
/etc/firewalld/zones/
directory only after they are modified. The default settings of the predefined zones are as follows:
-
block
-
-
Suitable for: Any incoming network connections are rejected with an icmp-host-prohibited message for
IPv4
and icmp6-adm-prohibited forIPv6
. Accepts: Only network connections initiated from within the system. Suitable for: Computers in your DMZ that are publicly-accessible with limited access to your internal network. Accepts: Only selected incoming connections. Suitable for: Any incoming network packets are dropped without any notification. Accepts: Only outgoing network connections.
-
Suitable for: Any incoming network connections are rejected with an icmp-host-prohibited message for
-
external
-
- Suitable for: External networks with masquerading enabled, especially for routers. Situations when you do not trust the other computers on the network. Accepts: Only selected incoming connections. Suitable for: Home environment where you mostly trust the other computers on the network. Accepts: Only selected incoming connections.
-
internal
-
- Suitable for: Internal networks where you mostly trust the other computers on the network. Accepts: Only selected incoming connections.
-
public
-
- Suitable for: Public areas where you do not trust other computers on the network. Accepts: Only selected incoming connections.
-
trusted
-
-
Accepts: All network connections.
Suitable for: Work environment where you mostly trust the other computers on the network.
Accepts: Only selected incoming connections.
One of these zones is set as the
default
zone. When interface connections are added to
NetworkManager
, they are assigned to the default zone. On installation, the default zone infirewalld
is thepublic
zone. You can change the default zone. Make network zone names self-explanatory to help users understand them quickly. To avoid any security problems, review the default zone configuration and disable any unnecessary services according to your needs and risk assessments.Additional resources
-
firewalld.zone(5)
man page
-
-
Accepts: All network connections.
Suitable for: Work environment where you mostly trust the other computers on the network.
Accepts: Only selected incoming connections.
One of these zones is set as the
default
zone. When interface connections are added to
40.3. Firewall policies
The firewall policies specify the desired security state of your network. They outline rules and actions to take for different types of traffic. Typically, the policies contain rules for the following types of traffic:
Incoming traffic
Outgoing traffic
Forward traffic
Specific services and applications
Network address translations (NAT)
Firewall policies use the concept of firewall zones. Each zone is associated with a specific set of firewall rules that determine the traffic allowed. Policies apply firewall rules in a stateful, unidirectional manner. This means you only consider one direction of the traffic. The traffic return path is implicitly allowed due to stateful filtering of
firewalld
.
Policies are associated with an ingress zone and an egress zone. The ingress zone is where the traffic originated (received). The egress zone is where the traffic leaves (sent).
The firewall rules defined in a policy can reference the firewall zones to apply consistent configurations across multiple network interfaces.
40.4. Firewall rules
You can use the firewall rules to implement specific configurations for allowing or blocking network traffic. As a result, you can control the flow of network traffic to protect your system from security threats.
Firewall rules typically define certain criteria based on various attributes. The attributes can be as:
Source IP addresses
Destination IP addresses
Transfer Protocols (TCP, UDP, …)
Ports
Network interfaces
The
firewalld
utility organizes the firewall rules into zones (such as
public
,
internal
, and others) and policies. Each zone has its own set of rules that determine the level of traffic freedom for network interfaces associated with a particular zone.
40.5. Zone configuration files
A
firewalld
zone configuration file contains the information for a zone. These are the zone description, services, ports, protocols, icmp-blocks, masquerade, forward-ports and rich language rules in an XML file format. The file name has to be
zone-name
.xml
where the length of
zone-name
is currently limited to 17 chars. The zone configuration files are located in the
/usr/lib/firewalld/zones/
and
/etc/firewalld/zones/
directories.
The following example shows a configuration that allows one service (
SSH
) and one port range, for both the
TCP
and
UDP
protocols:
<?xml version="1.0" encoding="utf-8"?> <short>My Zone</short> <description>Here you can describe the characteristic features of the zone.</description> <service name="ssh"/> <port protocol="udp" port="1025-65535"/> <port protocol="tcp" port="1025-65535"/> </zone>
Additional resources
-
firewalld.zone
manual page
40.6. Predefined firewalld services
The
firewalld
service is a predefined set of firewall rules that define access to a specific application or network service. Each service represents a combination of the following elements:
Local port
Network protocol
Associated firewall rules
Source ports and destinations
Firewall helper modules that load automatically if a service is enabled
A service simplifies packet filtering and saves you time because it achieves several tasks at once. For example,
firewalld
can perform the following tasks at once:
Open a port
Define network protocol
Enable packet forwarding
Service configuration options and generic file information are described in the
firewalld.service(5)
man page. The services are specified by means of individual XML configuration files, which are named in the following format:
service-name
.xml
. Protocol names are preferred over service or application names in
firewalld
.
You can configure
firewalld
in the following ways:
Use utilities:
firewall-config
- graphical utility
firewall-cmd
- command-line utility
firewall-offline-cmd
- command-line utility
Edit the XML files in the
/etc/firewalld/services/
directory.
If you do not add or change the service, no corresponding XML file exists in
/etc/firewalld/services/
. You can use the files in
/usr/lib/firewalld/services/
as templates.