Sub topic 2
Zones: how traffic is matched to a rule set
This chapter assumes basic Linux command-line use, sudo, systemctl, TCP and UDP ports, IPv4 addresses, and CIDR notation. You should also know that a listening service is different from a firewall rule: the service can listen on a port while the firewall still blocks traffic to it.
What a firewalld zone does
firewalld is a firewall manager for Linux. It uses firewall-cmd to manage rules while a background service applies those rules to network traffic.
A zone is a named rule set with a security level. Each zone can contain allowed services, ports, protocols, and additional rules. For example, the public zone commonly allows only services intended for public access, while the internal zone may allow more traffic from a trusted network.
A packet is matched to one zone. The rules in that zone then decide whether the packet is accepted, rejected, or dropped.
How traffic is assigned to a zone
A zone can be associated with:
- A source address or network, such as
203.0.113.0/24 - A network interface, such as
ens3 - Neither, in which case it can act as the default zone
Source-based assignments are useful when the same server should treat different networks differently. For example, traffic from a management subnet might use an internal zone, while traffic arriving from the internet uses public.
Interface-based assignments are common on servers with multiple network interfaces. An interface connected to a private network can use a more permissive zone than an interface connected to the internet.
A zone does not automatically describe the physical network. It describes how firewalld handles traffic that it assigns to that zone.
Inspecting zone assignments
Start by checking the default zone and the active assignments.
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --get-active-zonesThe default-zone command might return public. The active-zones command shows zones that currently have an interface or source assigned. It can look like this:
public
interfaces: ens3
internal
sources: 192.168.50.0/24This means traffic arriving through ens3 uses the public rules, unless it matches a more specific source assignment. Traffic from 192.168.50.0/24 uses the internal rules.
Check the complete rules for one zone with:
sudo firewall-cmd --zone=public --list-allThe output includes the zone target, interfaces, sources, services, ports, protocols, and rich rules. The services list contains predefined groups such as ssh or http. The ports list contains explicit port and protocol pairs such as 8080/tcp.
| Zone element | Example | Meaning |
|---|---|---|
| Interface | `ens3` | Traffic arriving through this interface uses the zone |
| Source | `192.168.50.0/24` | Traffic from this network uses the zone |
| Service | `ssh` | A predefined group of ports and protocols |
| Port | `8080/tcp` | TCP port 8080 is allowed in the zone |
Choosing the correct zone
Do not open a port merely because it appears in one zone. First identify the zone that will receive the traffic. Opening http in internal does not make HTTP available through an interface assigned to public.
For a single-interface internet server, the default public zone is often the relevant zone. For a multi-interface server, inspect every active zone and decide which network should reach the service.
Zone assignments and their rules can have separate runtime and permanent states. A later chapter covers that distinction in detail. When testing a change, always inspect the zone that is active for the traffic you are testing.
Exercise
A server shows public with interface ens3 and internal with source 192.168.50.0/24. Which zone handles a connection from 192.168.50.25 arriving through ens3?
Show answer
The source matches internal, so firewalld uses the internal zone for that connection. A connection from another source arriving through ens3 uses public.