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
相关推荐
Flash.kkl44 分钟前
Linux——进程信号
运维·服务器
苏宸啊2 小时前
Linux权限
linux·运维·服务器
Gofarlic_oms12 小时前
Windchill用户登录与模块访问失败问题排查与许可证诊断
大数据·运维·网络·数据库·人工智能
xqhoj2 小时前
Linux——make、makefile
linux·运维·服务器
文亭湖畔程序猿3 小时前
Debian 12 日常命令 & nano 快捷键速查表
运维·debian
张童瑶3 小时前
Linux 在线安装编译Python3.11
linux·运维·python3.11
ziqibit3 小时前
debian Live with Persistence 持久化U盘的debian系统
运维·debian
Shi_haoliu3 小时前
SolidTime 在 Rocky Linux 9.5 上的完整部署流程
linux·运维·nginx·postgresql·vue·php·laravel
Lkygo3 小时前
LlamaIndex使用指南
linux·开发语言·python·llama
qq_254617774 小时前
nslookup 这个命令解析dns,和系统接口gethostbyname解析区别在哪?
linux·网络