本帖最后由 yufeiluo 于 2018-01-25 21:01 编辑
下面的代码可以将那些反复尝试登录ssh的ip地址写入/etc/hosts.deny
- cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black.txt
- DEFINE="5"
- for i in `cat /root/black.txt`
- do
- IP=`echo $i |awk -F= '{print $1}'`
- NUM=`echo $i|awk -F= '{print $2}'`
- if [ $NUM -gt $DEFINE ];then
- grep $IP /etc/hosts.deny > /dev/null
- if [ $? -gt 0 ];then
- echo "sshd:$IP:deny" >> /etc/hosts.deny
- fi
- fi
- done
复制代码
基本上,我看懂了,有个疑问,写入/etc/hosts.deny后,是否需要重新启动机器? 机器会自动读取已经改变的/etc/hosts.deny文件吗? |