Linux添加白名单黑名单

Linux添加黑白名单
centos7用的是firewall 添加单个黑名单只需要把ip添加到 
/etc/hosts.deny
举例添加40.42 40.43添加黑名单

# # hosts.deny This file contains access rules which are used to # deny connections to network services that either use # the tcp_wrappers library or that have been # started through a tcp_wrappers-enabled xinetd. # # The rules in this file can also be set up in # /etc/hosts.allow with a 'deny' option instead. # # See 'man 5 hosts_options' and 'man 5 hosts_access' # for information on rule syntax. # See 'man tcpd' for information on tcp_wrappers # sshd:192.168.40.42:deny sshd:192.168.40.43:deny

centos7用的是firewall 添加单个白名单只需要把ip添加到 
/etc/hosts.allow
添加一个IP为白名单

# # hosts.allow This file contains access rules which are used to # allow or deny connections to network services that # either use the tcp_wrappers library or that have been # started through a tcp_wrappers-enabled xinetd. # # See 'man 5 hosts_options' and 'man 5 hosts_access' # for information on rule syntax. # See 'man tcpd' for information on tcp_wrappers sshd:all:allow

==============================================================================================================================================================
多次失败登录即封掉IP,防止暴力破解的脚本,超过20次的就加到黑名单
1、编辑脚本

vim /usr/local/bin/secure_ssh.sh #! /bin/bash cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /usr/local/bin/black.txt for i in `cat /usr/local/bin/black.txt` do IP=`echo $i |awk -F= '{print $1}'` NUM=`echo $i|awk -F= '{print $2}'` if [ $NUM -gt 20 ];then grep $IP /etc/hosts.deny > /dev/null if [ $? -gt 0 ];then echo "sshd:$IP:deny" >> /etc/hosts.deny fi fi done

2、创建记录登录失败次数的文件 
touch /usr/local/bin/black.txt
3、添加定时 10分钟执行一次  crontab -e
 */10 * * * * root  sh /usr/local/bin/secure_ssh.sh


__EOF__

本文作者朱辉彪
本文链接https://www.cnblogs.com/zhuhuibiao/p/16476259.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   后山人  阅读(3224)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-07-14 Linux在写入 ~/.bashrc文件内容错误,并且source了导致所有命令不可用
2021-07-14 Linux 安装mysql5.7.32
点击右上角即可分享
微信分享提示