DirectAdmin:Auto block IPs

2013年07月28日 / 技术相关 / 标签:directadmin,firewall,iptables,script

(1) The first part of thie guide will outline how to setup the actual firewall for the to use. Note that we're not able to offer any support for this setup, so use it at your own risk. Also, this file is written for a CentOS/Fedora type system and has not been tested on Debian or FreeBSD (it may work on Debian, not sure).

cd /etc/init.d
mv iptables iptables.backup
chmod 755 iptables

*** Note that it opens ssh on port 22, so make sure you either change it manually, or have physical access to your server if you're running ssh on some other port.

You'll want to test this out to ensure it works for you:

/etc/init.d/iptables restart

to make sure you can still connect to everything ok. If not, you may need to head to the datacenter to shut it off (partly why we don't offer support for firewalls)

(2) The second step is to install the so you can create a file that lists the IPs to be blocked. A sample can be found here.
To install this file, type:

cd /usr/local/directadmin/scripts/custom
wget -O
wget -O
wget -O
chmod 700

This should activate the button in DA at:
Admin Level -> Brute Force Monitor -> IP Info -> Block IP

This particular script will check to ensure that the IP you're blocking does not already exist in the list.
It will also generate the output from "iptables -nL" which should show you everything that is current blocked in the list. (iptables -nL is also output in the event the IP is already blocked, so you can see your iptables list without doing anything)

(3) Create the empty block list and exempt list files:

touch /root/blocked_ips.txt
touch /root/exempt_ips.txt
  1. This last step is optional and should only be used after you've tested the above setup for a while to get comfortable that you're not going to block yourself. The is only used for an active "click" by the Admin, it does not automate blocking. To automate blocking, install the following script:

    cd /usr/local/directadmin/scripts/custom
    wget -O
    chmod 700

If you're running FreeBSD with ipfw, you'd skip steps 1, 2 and 3, and instead, add the following code to the file:


echo "Blocking $ip with ipfw ...<br>";
ipfw add deny ip from $ip to any
exit $?

and don't forget to chmod the to 755.






  • php: 感谢可以用了
  • 厉害了!: 厉害了!!!真的可以安装运行了。
  • 赵赵: 还是不行 求大佬指导
  • 受害人: 感谢 十分感谢
  • 过路人: 这个方法很管用,直接安装多次都是失败 按照楼主的法子一次就搞定。谢谢!
  • yjl: 很久没更新了?
  • 阿策阳光: 博主威武,完美的解决了问题。
  • servers: 基本上很少用电信联通的了,太贵