查看失败的IP
iplist=$(/bin/lastb |awk '{print $3}'|sort|uniq -c|awk '{if ($1>1500) print $2}' | grep -v "^10.0.0.")
并将ip追加到黑名单
for ip in ${iplist}
do
echo ALL: ${ip} >> /etc/hosts.deny
# sshd 失败ip追加到黑名单
echo "sshd:112.192..:deny" >> /etc/hosts.deny
echo > /var/log/btmp
done
备注说明
通过/etc/hosts.deny 设置禁止建立连接的地址来源。如下演示ssh服务配置,其他服务sftp、telnet等同理。1、拒绝特定IP echo “sshd:192.168.0.2:deny” >> /etc/hosts.deny
2、拒绝特定IP段 echo “sshd:192.168.0.2/24:deny” >> /etc/hosts.deny
3、拒绝特定IP段 echo “sshd:192.168…:deny” >> /etc/hosts.deny
4、拒绝全部地址 echo “sshd:ALL” >> /etc/hosts.deny
本文介绍了如何通过Shell脚本查询失败的IP地址,如果数量超过1500次且不在特定范围内,将其添加到SSHhosts.deny文件中,以限制这些IP对ssh、sftp和telnet等服务的访问。
1287

被折叠的 条评论
为什么被折叠?



