Linux's service hosts are exposed to the Internet and are often harassed by illegal users. such as weak password scan, exploratory login;
All this poses a threat to Linux hosts. The following script will shut out the illegal user.
Principle: Get an attempt to log on to the Linux host user's IP, cut the number of failures more than 10, it is considered that such IP for the illegal user login, and then append their IP to the Iptables rule to filter, so that it can not communicate with the Linux host, the system every 10 minutes to perform.
#/bin/bash
rm-f/data/ip.txt 2>/dev/null
/sbin/iptables-f cat/var/log/secure|awk
'/Failed/{print $ ( NF-3)} ' |sort|uniq-c|awk ' {print $1,$2} ' >/data/ip.txt for
i in ' Cat/data/ip.txt|awk ' {if ($1>=10) {print $}} ' '
do
/sbin/iptables-i input-p all-s ${i}-j drop;sleep 1 done crontab-e */10 * * * *
/data/ip.sh & Gt /dev/null 2>&1
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/