I'm trying to configure a complex firewall for my team. We're looking at six interfaces with different types of security zones and flows.
I have a well-documented, clean firewall configuration script, but if I run iptables-save, the results will of course have no comments. The results will also be out of sync with our documented policy.
Is there a nice, clean way that I can use my own configuration file on Redhat without undoing Redhat's Rube Goldberg scripts? at the same time, I'd like to ensure that those same scripts don't stomp on my config or e.g., rip the firewall wide-open as soon as somebody does an ifdown/ifup.
I'd suggest writing a script, e.g.:
Then, edit
rc.local
and add:Right before the
exit 0
line.Now, if you need to modify your firewall, just edit and execute the first script.
The easiest way to manage your iptables configs on RHEL is to simply ignore the system provided config scripts entirely. I manage all of my RHEL systems with puppet, and use a fragments based approach as per Module Iptables Patterns.
This may not work for you if you're not a puppet shop, but at it's base all this does is build out the file
/etc/sysconfig/iptables
directly. That approach will likely work very well for you. In this way you can still keep your comments, and order the rules however you would like.As I've already said IMHO writing SHELL scripts for configuring iptables is a dumb approach.
iptables own facilities allow implementing 99.99 % of policies w/o need to bring in some additional things like SHELL-scripting, for e. g.
If you need comments to be saved inside your iptables config, you use
-m comment --comment ""
You could make your own startup script and add it to your existing services with chkconfig.
Here's a template that I often use.
It flushes all rules in place and replaces them with a custom set that allows ssh, http and https in.
You could simple put this script inside
/etc/init.d/
, make it executable and runchkconfig firewall --add && chkconfig firewall on
.You can now enable the firewall with
service firewall start
,service firewall panic
stops all network traffic andservice firewall stop
disables the firewall.I think you get the idea.
The major advantage of this system is that you have one script that you can heavily customize and write comments in, without touching any of the existing iptables settings of the OS.