-
-
Save fboaventura/5fdd3997febe7b9102862b684aea2acc to your computer and use it in GitHub Desktop.
Simple spamhaus ipset firewall block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
## Run every 24h via cron | |
## Old entries will time out later automatically | |
( | |
cd /var/lib/firewall | |
wget -qN 'http://www.spamhaus.org/drop/drop.txt' | |
ipset create -exist spamhaus_drop hash:net counters timeout 90000 comment | |
for line in $(cat drop.txt | grep -i SBL | cut -f 1 -d ';') | |
do | |
if [[ $line =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}$ ]]; then | |
ipset -! add spamhaus_drop "$line" comment "$(date)" | |
fi | |
done | |
#iptables -I INPUT -m set --match-set spamhaus_drop src -j DROP | |
#iptables -I INPUT -m set --match-set spamhaus_drop src -m hashlimit --hashlimit 1/second --hashlimit-name logging --hashlimit-mode srcip --jump LOG --log-level warning --log-prefix "SPAMHAUS_DROP: " | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment