fail2ban防护爆破攻击极速安装配置教程

Admin 运维笔记1 1,4293字数 1150

Fail2Ban 是一款入侵防御软件,可以保护服务器免受暴力攻击。Fail2Ban 在运行时会监听日志文件,根据指定的规则解析日志内容,检测到失败日志后,可自动更新防火墙规则,封禁IP地址。

 文章源自新逸网络-https://www.xinac.net/9264.html

本文介绍fail2ban的极速安装过程,及配置文件的修改,可以最快的完成安装。文章源自新逸网络-https://www.xinac.net/9264.html

在线安装

apt install fail2ban
or
yum install fail2ban

# 在线安装建议不要看了,直接看下边的源码安装

源码安装

# 下载源码包并解压
cd /opt && \
wget https://git.xinac.net/jinql/fail2ban/archive/0.10.6.tar.gz && \
tar -zxvf 0.10.6.tar.gz && \
cd fail2ban

# 安装
python setup.py install
cp files/redhat-initd /etc/init.d/fail2ban
chmod +x /etc/init.d/fail2ban
chkconfig fail2ban on

配置文件

# 现有的配置文件不要直接修改,一般只需修改 jail.local
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
vim /etc/fail2ban/jail.local

# 填入以下内容
[DEFAULT]
ignoreip = 127.0.0.1/8
bantime = 600
findtime = 300
maxretry = 5
banaction = firewallcmd-ipset
action = %(action_mwl)s

[sshd]
enabled = true
filter = sshd
port = 22
maxretry = 5
findtime = 300
bantime = 1800
banaction = firewallcmd-ipset
action = %(action_mwl)s
logpath = /var/log/secure

配置说明

文章源自新逸网络-https://www.xinac.net/9264.html

[DEFAULT] 块,表示默认设置,300 秒内检测到同一IP的 5 次失败日志,封禁该IP 600文章源自新逸网络-https://www.xinac.net/9264.html

 文章源自新逸网络-https://www.xinac.net/9264.html

[sshd] 块,表示对ssh服务的处理文章源自新逸网络-https://www.xinac.net/9264.html

  1. enabled = true,表示启用此项配置,默认是 false
  2. banaction = firewallcmd-ipset,表示使用firewallcmd防火墙工具封禁IP,不想开启防火墙的可以改为hostsdeny
  3. logpath,日志文件的位置,debian系列需改为/var/log/auth.log

启动

# 启动 fail2ban
/etc/init.d/fail2ban start

# 查看运行状态
fail2ban-client status
fail2ban-client status sshd

 文章源自新逸网络-https://www.xinac.net/9264.html

OK,大功告成,后续再介绍封禁IP后发送消息提醒文章源自新逸网络-https://www.xinac.net/9264.html

 文章源自新逸网络-https://www.xinac.net/9264.html 文章源自新逸网络-https://www.xinac.net/9264.html

weinxin
新逸IT技术
扫一扫关注微信公众号
Admin
  • 本文由 发表于 2022-04-25
  • 转载请注明:https://www.xinac.net/9264.html
CentOS系统openssh升级教程 运维笔记

CentOS系统openssh升级教程

注意:升级openssh版本有风险,升级过程中不能中断!否则服务器有失联的风险。使用VPN连接远程操作的,网络不稳定的请勿操作。 按本教程操作,网络稳定的情况下,99%的都会成功。 网上很多教程先安装...
评论  1  访客  1
    • 逸风
      逸风 0

      匿名网友

    匿名

    发表评论

    匿名网友

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    确定