CentOS下使用Fail2ban来禁止指定IP访问的方法

2023-12-04 0 277

安装和配置

fail2ban工具通过分析日志来自动 ban 入侵者的IP,下载地址在:http://fail2ban.sourceforge.net/rpms/找到最新版本的 rpm 包来安装,装好后,稍微根据自己的情况改一下配置就可以使用了。复制代码代码如下:vi /etc/fail2ban.conf#以 daemon 方式启动 fail2banbackground = true#允许尝试次数maxfailures = 3#触发 maxfailures 之後的封锁时间(秒); 设为 -1 表示永远封锁bantime = 3600#以 findtime (秒) 时间内的错误记录作为 maxfailures 的计数基准findtime = 600#排除 IP 范围, 以空白隔开ignoreip = 127.0.0.1 192.168.0.0/24#不启用 mail 通知[MAIL]enabled = false#修改自 VSFTPD, 未提及的部份保持原设定[PROFTPD]enabled = truelogfile = /var/log/proftpd/proftpd.logfailregex = no such user|Incorrect password#未提及的部份保持原设定[SSH]enabled = truelogfile = /var/log/secureservice fail2ban start这个服务启动以后,每天都能在 /var/log/fail2ban.log 中看到有攻击的肉鸡被 ban 了。复制代码代码如下:2015-08-01 09:13:33,532 WARNING: SSH: Ban (3600 s) 205.189.197.662015-08-01 12:24:41,943 WARNING: SSH: Ban (3600 s) 121.52.209.5

移除被 Fail2ban 禁止的 IP如果你已经安装并使用了 fail2ban 来保护你的 web 服务器,你也许会想知道如何在 CentOS 6、CentOS 7、RHEL 6、RHEL 7 和 Oracle Linux 6/7 中找到被 fail2ban 阻止的 IP,或者你想将 ip 从 fail2ban 监狱中移除。要查看所有被禁止的 ip 地址,运行下面的命令:复制代码代码如下:# iptables -LChain INPUT (policy ACCEPT)target prot opt source destinationf2b-AccessForbidden tcp — anywhere anywhere tcp dpt:httpf2b-WPLogin tcp — anywhere anywhere tcp dpt:httpf2b-ConnLimit tcp — anywhere anywhere tcp dpt:httpf2b-ReqLimit tcp — anywhere anywhere tcp dpt:httpf2b-NoAuthFailures tcp — anywhere anywhere tcp dpt:httpf2b-SSH tcp — anywhere anywhere tcp dpt:sshf2b-php-url-open tcp — anywhere anywhere tcp dpt:httpf2b-nginx-http-auth tcp — anywhere anywhere multiport dports http,httpsACCEPT all — anywhere anywhere state RELATED,ESTABLISHEDACCEPT icmp — anywhere anywhereACCEPT all — anywhere anywhereACCEPT tcp — anywhere anywhere tcp dpt:EtherNet/IP-1ACCEPT tcp — anywhere anywhere tcp dpt:httpREJECT all — anywhere anywhere reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)target prot opt source destinationREJECT all — anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)target prot opt source destinationChain f2b-NoAuthFailures (1 references)target prot opt source destinationREJECT all — 64.68.50.128 anywhere reject-with icmp-port-unreachableREJECT all — 104.194.26.205 anywhere reject-with icmp-port-unreachableRETURN all — anywhere anywhere从 Fail2ban 中移除 IP复制代码代码如下:# iptables -D f2b-NoAuthFailures -s banned_ip -j REJECT

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 RedHat/Centos CentOS下使用Fail2ban来禁止指定IP访问的方法 https://www.u-9.cn/system/redhatcentos/79339.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务