Skip to content

Instantly share code, notes, and snippets.

@ckhung
Last active December 3, 2019 02:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckhung/af3c5eab631ee76fc67575d3f0dd0b0c to your computer and use it in GitHub Desktop.
Save ckhung/af3c5eab631ee76fc67575d3f0dd0b0c to your computer and use it in GitHub Desktop.
daily cron script to ban (for a longer time) sites repeatedly banned by fail2ban
#!/bin/sh
# 詳見: 「fail2ban: 新手老手 root 網管都要練的金鐘罩」
# http://newtoypia.blogspot.tw/2016/04/fail2ban.html
sed -i.bak '/repeated-fail2ban/,+1d' /etc/hosts.deny
/etc/fail2ban/repeated-fail2ban.pl -d 7 -g 3 -i 10 >> /etc/hosts.deny
cat <<EOF > /etc/apache2/conf.d/repeated-fail2ban
<Location />
Order Allow,Deny
Allow from all
EOF
/etc/fail2ban/repeated-fail2ban.pl -f apache2 -d 7 -g 3 -i 10 | sed 's/^/\t/' >> /etc/apache2/conf.d/repeated-fail2ban
echo "</Location>" >> /etc/apache2/conf.d/repeated-fail2ban
service apache2 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment