Skip to content

Instantly share code, notes, and snippets.

@AysadKozanoglu
Created April 10, 2016 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AysadKozanoglu/a95346de3dc748ab03eb7bdbbd6b73b6 to your computer and use it in GitHub Desktop.
Save AysadKozanoglu/a95346de3dc748ab03eb7bdbbd6b73b6 to your computer and use it in GitHub Desktop.
spamhaus blacklisted iptable blocker script
#!/bin/bash
IPT=”/bin/iptables”
FILE=”/tmp/drop.lasso”
URL=”http://www.spamhaus.org/drop/drop.lasso”
echo “”
echo -n “Deleting DROP list from existing firewall…”
#This will delete all dropped ips from firewall
ipdel=$(cat $FILE | egrep -v ‘^;’ | awk ‘{ print $1}’)
for ipblock in $ipdel
do
$IPT -D spamhaus-droplist -s $ipblock -j DROP
$IPT -D droplist -s $ipblock -j LOG –log-prefix “DROP Spamhaus List”
done
echo -n “Applying DROP list to existing firewall…”
#This will drop all ips from spamhaus list.
[ -f $FILE ] && /bin/rm -f $FILE || :
cd /tmp
wget $URL
blocks=$(cat $FILE | egrep -v ‘^;’ | awk ‘{ print $1}’)
$IPT -N spamhaus-droplist
for ipblock in $blocks
do
$IPT -A droplist -s $ipblock -j LOG –log-prefix “DROP Spamhaus List”
$IPT -A droplist -s $ipblock -j DROP
done
$IPT -I INPUT -j droplist
$IPT -I OUTPUT -j droplist
$IPT -I FORWARD -j droplist
echo “…Done”
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment