CentOS 7 安装fail2ban hostdeny方式封禁ip —— 筑梦之路

centos 7 换源参考CentOS 7.9 停止维护(2024-6-30)后可用在线yum源 ------ 筑梦之路_centos停止维护-CSDN博客

安装fail2ban

bash 复制代码
yum install fail2ban

新增配置文件

bash 复制代码
cat > /etc/fail2ban/action.d/hostsdeny.conf << EOF
[Definition]
actionstart =
actionstop =
actioncheck =
actionban = echo "ALL: <ip>" >> /etc/hosts.deny
actionunban = sed -i.bak "/\<ip\>/d" /etc/hosts.deny
EOF

cat > /etc/fail2ban/jail.local << EOF
#defalut这里是设定全局设置,如果下面的监控没有设置就以全局设置的值设置。
[DEFAULT]
# 用于指定哪些地址ip可以忽略 fail2ban 防御,以空格间隔。
ignoreip = 127.0.0.1/8
# 客户端主机被禁止的时长(默认单位为秒)
bantime  = 86400
# 过滤的时长(秒)
findtime  = 600
# 匹配到的阈值(次数)
maxretry = 5
    
[ssh-iptables]
# 是否开启
enabled  = true
# 过滤规则
filter   = sshd
port    = 22
# 动作  发送邮件一定要加在action 后面,一定要注意位置
#action   = hostsdeny
banaction = hostsdeny
banaction_allports = hostsdeny-allports
# 日志文件的路径
logpath  = /var/log/secure
# 匹配到的阈值(次数)
maxretry = 5
EOF

启动服务

bash 复制代码
systemctl enable fail2ban --now

# 查看被封禁的ip

fail2ban-client status ssh-iptables
相关推荐
十日十行11 小时前
Linux和window共享文件夹
linux
木心月转码ing19 小时前
WSL+Cpp开发环境配置
linux
蝎子莱莱爱打怪2 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀2 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应2 天前
vi编辑器使用
linux·后端·操作系统
何中应2 天前
Linux进程无法被kill
linux·后端·操作系统
何中应2 天前
rm-rf /命令操作介绍
linux·后端·操作系统
何中应2 天前
Linux常用命令
linux·操作系统
葛立国2 天前
从 / 和 /dev 说起:Linux 文件系统与挂载点一文理清
linux
DianSan_ERP2 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet