I’ve been using FirewallD for years now, and it’s still not clear to me how the developers intended it to be configured, particularly when a zone’s target is set to default
. Here’s what I usually do:
Let’s say source A needs access to https. I would create a new zone for source A and add https:
firewall-cmd --permanent --new-zone zone-a
firewall-cmd --permanent --zone zone-a --add-source 1.0.0.0/24
firewall-cmd --permanent --zone zone-a --add-service https
firewall-cmd --reload
Let’s say source B needs access to mysql. I would create a zone-b for source B just like I did for source A above, except add the mysql service to it. If the source has a large list of IP addresses or networks, I might organize those into ipsets before adding the ipsets to a zone, but the above example is the gist of what I’ve always done. I really like organizing the sources of the traffic I need to control into zones based on the role that source plays in the network (e.g. sources for different VLANs, categories of servers, vendors, etc.) Note that I always set AllowZoneDrifting=no
in firewalld.conf.
I always leave my zones’ targets set to default
, which is where all my confusion is coming from. If I set a zone’s target to ACCEPT
, DROP
, or %%REJECT%%
, any traffic matching the zone’s sources OR ports/services will be accepted, dropped, or rejected. Using my example above, if I were to set zone-a’s target to ACCEPT
, traffic from 1.0.0.0/24 would be accepted, as well as any traffic destined to port 443. It wouldn’t only allow traffic from 1.0.0.0/24 to port 443, it would also allow traffic from 1.0.0.0/24 to ANY port, and also allow traffic from ANY source to port 443. This has always seemed very odd to me, and I can’t imagine a situation where I would want this. This is why I’ve always left a zone’s target set to default
, which will only accept traffic from the zone’s sources to the zone’s ports/services, and reject everything else.
While the default
target seems to get me what I want, the true behavior as documented is incredibly confusing. I see people around the internet saying it’s basically the same as %%REJECT%%
. If it were the same as %%REJECT%%
, wouldn’t traffic from networks defined in the zone’s sources be rejected? There’s also this GitHub post that seems to get referenced whenever this topic comes up. This post is a suggested clarification to the firewalld.zone
man page, which states that the default
target will reject, except in three specific scenarios. None of the listed scenarios are the scenario I frequently rely on where traffic gets accepted if the source matches the zone’s sources and the destination matches zone’s ports/services. According to this documentation, shouldn’t traffic from my zone’s sources be getting rejected? In fact, it’s traffic that doesn’t match my zone’s sources or services that gets rejected.
The last thing I’m struggling to understand is FirewallD’s lack of an obvious implicit deny rule. With traditional firewall configs made up of a single list of rules that traffic matches, there’s typically an implicit deny at the bottom of the list for traffic that doesn’t match any of the rules. For iptables, this is where you can decide whether or not you want traffic to be dropped or rejected. I’m in a situation now where I need to change FirewallD’s default %%REJECT%%
behavior to DROP
instead, and I have no idea how to do that. I’ve seen some discussions online say it’s impossible. I’m sure this has to do with me not understanding the default
target.
My wall of text boils down to the following questions:
- To allow traffic from a specific set of source networks to a set of ports, is my method of using a zone to correlate the source networks with the destination ports best practice?
- What is the intention of the
default
target? Is there behavior that the documentation doesn’t outline, or is my scenario actually mentioned in the documentation and I’m misinterpreting it? - What is FirewallD’s version of an implicit deny rule? How can I make it
DROP
by default instead of%%REJECT%%
?
I appreciate anyone who takes the time to read this.