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
相关推荐
小猿姐1 小时前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
七歌杜金房6 小时前
我终于又有了自己的 Linux 电脑
linux·debian·mac
SkyWalking中文站13 小时前
认识 Horizon UI · 5/17:3D 基础设施地图
运维·监控·自动化运维
tntxia1 天前
linux curl命令详解_curl详解
linux
扛枪的书生1 天前
Linux 网络管理器用法速查
linux
SkyWalking中文站1 天前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
顺风尿一寸1 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
雪梨酱QAQ2 天前
Kubeneters HA Cluster部署
运维
江华森2 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维
江华森2 天前
Matplotlib 数据绘图基础入门
运维