Sub topic 9
Blocking a Source Address or Network with Zones
This chapter assumes you know basic Linux commands, sudo, TCP and UDP ports, systemctl, and IPv4 CIDR notation. A CIDR network such as 203.0.113.0/24 represents a range of addresses. In this example, the range contains addresses from 203.0.113.0 through 203.0.113.255.
How source-based zones work
A firewalld zone is a set of firewall rules. Usually, firewalld selects a zone from a network interface. You can also assign a source address or network to a zone.
When traffic comes from a source assigned to a zone, firewalld applies that zone's policy to the traffic. This lets you handle one network differently from other traffic arriving through the same interface.
The drop zone silently discards incoming packets. The sender normally receives no response. This differs from the reject action, which sends an error response when possible.
Assign a network to the drop zone
The following commands add a source network to the permanent configuration of the drop zone. The reload activates the change.
sudo firewall-cmd --permanent --zone=drop --add-source=203.0.113.0/24
sudo firewall-cmd --reload
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=drop --list-allThe active-zone output should show the source under drop, similar to this:
drop
sources: 203.0.113.0/24The --permanent option changes the saved configuration. The --reload command then loads that saved configuration into the running firewall. Without the reload, the source will not be blocked immediately.
You can assign a single address instead of a network:
sudo firewall-cmd --permanent --zone=drop --add-source=203.0.113.10/32
sudo firewall-cmd --reloadThe /32 means one IPv4 address. Use the address format supported by your firewalld and IP version configuration when working with IPv6.
Remove a blocked source
To stop assigning a network to the drop zone, remove the source from the permanent configuration and reload:
sudo firewall-cmd --permanent --zone=drop --remove-source=203.0.113.0/24
sudo firewall-cmd --reload
sudo firewall-cmd --zone=drop --list-allRemoving the source does not necessarily open every service. It only stops applying the drop zone to that source. The source will then be evaluated using the zone selected by the interface or another source assignment.
Choose between drop and reject
Use drop when you want blocked traffic to receive no response. This can reduce information exposed to unwanted sources, but it can make troubleshooting slower because the client sees a timeout.
Use reject when clients should receive a quick failure. A reject policy is useful when you control the clients and want them to fail promptly. You can place a source in another zone with suitable rules, but source-based zones apply a complete zone policy, not just one isolated port rule.
| Goal | Suitable approach | Client's usual result |
|---|---|---|
| Silently discard traffic from a network | Assign the source to `drop` | Timeout |
| Allow only selected services from a trusted network | Assign the source to a restrictive custom zone | Allowed services work; others are denied |
| Block one source only for one port | Use a rich rule | Other ports follow the normal zone |
Check both the source assignment and the resulting rules when diagnosing a policy:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=drop --list-sources
sudo firewall-cmd --zone=drop --list-allExercise
What command sequence permanently assigns 198.51.100.0/24 to the drop zone and activates the change?
Show answer
Run sudo firewall-cmd --permanent --zone=drop --add-source=198.51.100.0/24, followed by sudo firewall-cmd --reload. Verify it with sudo firewall-cmd --zone=drop --list-sources.