I manage high traffic web servers that are constantly under attack. To manage the security of these web servers, I need to routinely update my iptables rules, and by routinely, I mean every morning when I roll into the office.
When I searched for a solution that allowed me to dynamically define my rules with a merge option, nothing come to the forefront. There are some miscellaneous posts about using PERL and cat, but nothing really useful.
Then I remember M4. If you don't know about M4, then you should man it.
Here's what you do.
iptables.m4:
This is the driver for the m4 process. When you want to create the iptables file, you just run:
m4 iptables.m4 > iptables
Here is a nifty script that does it all:
This script will create a backup file for you so you don't clobber your current config with a bad m4 parse.
Just save that script into something like "update.x" and chmod +x on it. Then you can update components of your iptables rule file much more easily.
Quick and easy solution. No perl junk, no expensive security management software, nothing but runtime macro substitution with M4.
When I searched for a solution that allowed me to dynamically define my rules with a merge option, nothing come to the forefront. There are some miscellaneous posts about using PERL and cat, but nothing really useful.
Then I remember M4. If you don't know about M4, then you should man it.
Here's what you do.
iptables.m4:
---- start ----
# Firewall configuration written by
# system-config-securitylevel
# Manual customization of this file is not
# recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
include(/root/iptables/iptables_special)
include(/root/iptables/iptables_reject)
include(/root/iptables/iptables_accept)
#
# The final rule that rejects everything
# that does not match
# the other explicit rules
#
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
----- end -----
This is the driver for the m4 process. When you want to create the iptables file, you just run:
m4 iptables.m4 > iptables
Here is a nifty script that does it all:
---- start ----
rm -f iptables
cp -f /etc/sysconfig/iptables iptables_back_`date +%Y%m%d`
m4 iptables.m4 > iptables
cp -f iptables /etc/sysconfig/
/etc/rc.d/init.d/iptables restart
---- end ----
This script will create a backup file for you so you don't clobber your current config with a bad m4 parse.
Just save that script into something like "update.x" and chmod +x on it. Then you can update components of your iptables rule file much more easily.
Quick and easy solution. No perl junk, no expensive security management software, nothing but runtime macro substitution with M4.