把一直尝试登录服务器的非法ip加入防火墙黑名单,可以按这个思路扩展为把攻击的ip加入防火墙黑名单。
有问题欢迎指教,感恩啦。
#!/bin/bash
##block the illegal ip that attempt to access server
##
#1.get the illegal ip
cat /var/log/secure |grep 'Failed password for root'| awk '{print $11}' | uniq -c|awk '{if($1>20){print $2}}' > blacklist
#2.get the illegal ip that be blocked already
iptables --list | grep DROP | awk '{print $4}' > blocked_ip
#3.create block_ip, ip in blacklist not in blocked_ip
grep -vFf blocked_ip blacklist > block_ip
while read line
do
echo $line
iptables -I INPUT -s $line -j DROP
done < block_ip
阅读(2241) | 评论(0) | 转发(0) |