How to config DirectAdmin to automatic block IP when found brute force on Debian 6 64-bit



DirectAdmin since version 1.39 has function to detect brute force attack (Info) but DirectAdmin didn't block IP that brute force us. It just warn and annoy us by sending an email. DirectAdmin already provide how to automatic block IP when detect brute force for CentOS/Fedora here but they didn't provide for Debian so I will do for you

  • First you have to install iptables
apt-get install iptables
  • Then create script file at /usr/local/directadmin/scripts/custom/
        echo "<br><br><textarea cols=160 rows=60>";
        /sbin/iptables -nL
        echo "</textarea>";
### Make sure it's not already blocked
COUNT=`grep -c $ip /etc/network/`;
if [ "$COUNT" -ne 0 ]; then
        echo "$ip already exists in iptables ($COUNT). Not blocking.";
        exit 2;
echo "Adding $ip to iptables...<br>";
/sbin/iptables -I INPUT -s $ip -j DROP
/sbin/iptables-save > /etc/network/
echo "<br><br>Result:";
exit 0;

Then change permission to 700

chmod 700 /usr/local/directadmin/scripts/custom/

This script will add Block This IP button in DirectAdmin Administrator > Brute Force Monitor then click IP Info on IP that we want to block

  • If you want iptables to be restored everytime when reboot. Put
post-up iptables-restore /etc/network/

at the bottom of interface in /etc/network/interfaces

  • If you want DirectAdmin to block ip automatically. Create script file /directadmin/scripts/custom/
ip=$value $SCRIPT
exit $?;

Then change permission to 700

chmod 700 /usr/local/directadmin/scripts/custom/

You can set the brute force time before that IP will be blocked by go to DirectAdmin Administrator > Administrator Settings > Notify Admins after an IP has and put the number you want

  • If you want to unblock IP. You still have to manual put this command by yourself
iptables -D INPUT -s -j DROP
iptables-save > /etc/network/

Change to IP that you want to unblock

I wish to have a so I can block IPs through DirectAdmin
How to block an IP in Linux