Quote:
|
Originally Posted by Elomis
Ooh. Good idea. Pity it can't be modular in that it can point to the file which I can then update, but I guess I am asking too much from a simple firwall implementatin.
Thanks.
|
You can point it to any file that you want and you can update the file with new entries one per line, the only thing is you would need to reload the script to re-read and add rules to it.
Or you could create a cron job that runs a script to update and read your file for you and add the rules on the fly. All rules that you add with show if you use
iptables-L, so you could have the script check the /etc/ipblock for entries and then check then against the current rules.
This way you could have them block the instant the rule applies, rather than having to reload the iptables script all the time. Just put together a little scipt that seems to work, although I haven't tested it extensively, you could also expand the script to check your log files as well and add entries from any host doing things they shouldn't be doing.
Code:
#!/bin/bash
BLOCK_LIST=`cat /etc/ipblock`
CURRENT_RULES=`iptables -L`
IPTABLES=`whereis iptables | awk '{print $2}'`
for ENTRIES in $BLOCK_LIST; do
SUCCESS=0
grep "$ENTRIES" "$CURRENT_RULES"
if [ ! "$?" = "$SUCCESS" ]; then # if the rule is not found, add it
$IPTABLES -I INPUT -i eth0 -s $ENTRIES -j DROP
$IPTABLES -I OUTPUT -o eth0 -d $ENTRIES -j DROP
fi
done
Using the -I (insert) rather than the -A (append) in the rule will place it at the the top, this makes sure you will get the drop rule first.