资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

用fail2ban给centos系统做防御-创新互联

系统为centos 6.4 64位

成都创新互联作为成都网站建设公司,专注重庆网站建设公司、网站设计,有关成都定制网站方案、改版、费用等问题,行业涉及成都木制凉亭等多个领域,已为上千家企业服务,得到了客户的尊重与认可。

fail2ban http://www.fail2ban.org/wiki/index.php/Main_Page

Fail2Ban is able to reduce the rate of incorrect authentications attempts however it cannot eliminate the risk that weak authentication presents. Configure services to use only two factor or public/private authentication mechanisms if you really want to protect services.

http://www.onerussian.com/tmp/fail2ban-pycon2014.pdf 这个是pdf的说明文档,不过较简单

fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽),如:当有人在试探你的SSH、SMTP、FTP密码,只要达到你预设的次数,fail2ban就会调用防火墙屏蔽这个IP,而且可以发送e-mail通知系统管理员

我们需要对ssh的非法登陆有一定的机制,fail2ban就可以做到

下载:https://codeload.github.com/fail2ban/fail2ban/tar.gz/0.8.13

安装:

tar -xzf fail2ban-0.8.13.tar.gz
cd fail2ban-0.8.13
python setup.py install 
cd files/
cp ./redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban

配置目录:/etc/fail2ban

/etc/fail2ban/action.d #firewall、iptables、mail、sendmail等配置文件

/etc/fail2ban/filter.d  #apache、nagios、nginx-http-auth、php-url-fopen、selinux-ssh等防护策略

/etc/fail2ban/jail.conf #主要配置文件

编辑配置文件:

vim /etc/fail2ban/jail.conf  #在#[ssh-iptables]  #enabled = true 两行的下面添加

[ssh-iptables]
enabled = true
filter = sshd
action  = iptables[name=SSH, port=ssh, protocol=tcp]
       sendmail-whois[name=SSH,dest=your_mail@163.com,sender=root@localhost,sendername="Fail2Ban"]
logpath  = /var/log/secure   #提供分析的日志,centos默认是这个路径
axretry = 5               #尝试次数
bantime = 172800          #拒绝时间/秒
  
  
[DEFAULT]                 #以下是约束下面的全局配置,不要添加
ignoreip = 127.0.0.1/8    #忽略的ip
bantime  = 600            #屏蔽时间
findtime  = 600           #在这个时间段内
maxretry = 3              #错误次数
backend = auto
usedns = warn

如果修改上面的[ssh-iptables]选项,那么将下面的[ssh-iptables]选项注释或删除,要不两个相同的选项设置,服务会不起作用

下面还有好多选项,enabled  = false 改为enabled  = true 就会生效

相应的配置文件路径:  /etc/fail2ban/filter.d/  也需要修改一下

启动服务:

service fail2ban restart

fail2ban的进程

/usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock -p /var/run/fail2ban/fail2ban.pid -x

查看状态:

fail2ban-client status

查看被阻止的ip

iptables -L

REJECT   all  --  192.168.22.236    anywhere       reject-with icmp-port-unreachable

如果重起iptables 记的一定还要重起fail2ban,不然不能生效,fail2ban的过滤表是在iptables 启动后在加入的

用fail2ban给centos系统做防御

如果有这个错误提示,把[ssh-iptables]前面的空格去掉

Starting fail2ban: ERROR  Failed during configuration: File contains no section headers.

file: /etc/fail2ban/jail.conf, line: 17

' [ssh-iptables]\n'

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:用fail2ban给centos系统做防御-创新互联
标题来源:http://cdkjz.cn/article/dgeeoe.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220