I'm migrating from iptables to firewalld, using Centos 7.
In the old times, I used to write the (permament) iptables rules in the /etc/sysconfig/iptables
, which also served to place comments prepended by #
(to remind us why we restricted this or that ip, etc).
Now, it seems that the current (permanent) configuration is read from /etc/firewalld/
files (especially /etc/firewalld/zones/*.xml
). I guess I could add xml comments there, but it seems the good practice is not to edit those files directly but via firewall-cmd
(no?).
Hence, I'm not sure which is the standard or recommended way to add comments to the rules.
Any suggestions?
Edited: For the record, I've verified that xml comments do not survive firewall-cmd
modifications.
As of 2/2020, I think
firewalld
use sufficiently widespread that ease of annotating rules either fromfirewall-cmd
or fromfirewall-config
is very important, for reasons discussed in the OP.Suggestions that we document rules in a CMS, via
firewall-cmd --direct
, via ipsets, or edit zone files manually, all complicate management and defeat a purpose offirewalld
, that of making firewall configuration more transparent.Therefore, until
firewall-cmd --comment
becomes available, I will annotate my rules via thelog prefix
option tofirewall-cmd --add-rich-rule
. For example,The resulting annotation appears in my system log as a side-effect, but now output of
firewall-cmd --list-all-zones
is self-documenting:The comment is also recorded in my zone file as:
I realize that even this approach overly complicates configuration by introducing rich rules, but believe the benefit in annotation worthwhile for now.
Although in the firewall-cmd man page, there is a section on Direct Options, that allow you to give parameters, so you could do something like:
firewall-cmd --direct --add-rule <table> <chain> <priority> <args> -c <some comment>
Although, as Michael Hampton said, probably not the best thing.
Thinking it over, I'm finding this
firewalld-cmd
thing slightly silly. After all, XML configuration files are human editable. It makes little sense to me, having to learn an extra layer of commands (well, one command, but with tons of arguments) only to edit some simple and neat XML files (*).I fell slightly stupid typing
firewall-cmd --permanent --zone=work --add-port=445/tcp
just for addding the following line to
/etc/firewalld/zones/work.xml
<port protocol="tcp" port="445"/>
Hence, at least for now, and considering that the XML elements don't include comment attributes (there are some requests in that direction) I'm leaning towards the following strategy: just forget about
firewalld-cmd
(perhaps even delete it), edit the XML files yourself, and add XML comments freely.(*) It's true that
firewalld-cmd
allows also to add dynamic (non permanent) rules. But I'd bet that that is not a very frequent scenario.