fail2ban是通过读取应用日志,对尝试爆破登陆的ip进行防火墙封禁的开源应用。

1. 配置文件丢失问题

/etc/fail2ban目录下只有空文件夹,没有jail.conf等配置文件

root@a-20250612-1519:/etc/fail2ban# ll
total 24
drwxr-xr-x   6 root root 4096 Jun 23 10:11 ./
drwxr-xr-x 105 root root 4096 Jun 23 10:11 ../
drwxr-xr-x   2 root root 4096 Jun 23 10:11 action.d/
drwxr-xr-x   2 root root 4096 Mar  2  2020 fail2ban.d/
drwxr-xr-x   3 root root 4096 Jun 23 10:11 filter.d/
drwxr-xr-x   2 root root 4096 Jun 23 10:11 jail.d/

apt remove卸载后重复安装导致,apt remove只会卸载应用,不会清空配置信息,apr purgeapt remove --purge会卸载应用并清空配置文件。
解决办法,执行apt remove --purge fail2ban,再执行apt install fail2ban
https://github.com/fail2ban/fail2ban/issues/3327

2. fail2ban服务启动失败
ubuntu@a-20250612-1519:/var/log/journal/08ebed7bf7174e3dbc4207086caa9635$ systemctl status fail2ban
● fail2ban.service - Fail2Ban Service
     Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2025-06-23 17:32:52 HKT; 15h ago
       Docs: man:fail2ban(1)
    Process: 3447 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
    Process: 3448 ExecStart=/usr/bin/fail2ban-server -xf start (code=exited, status=255/EXCEPTION)
   Main PID: 3448 (code=exited, status=255/EXCEPTION)

Jun 23 17:32:52 a-20250612-1519 systemd[1]: Starting Fail2Ban Service...
Jun 23 17:32:52 a-20250612-1519 systemd[1]: Started Fail2Ban Service.
Jun 23 17:32:52 a-20250612-1519 fail2ban-server[3448]: 2025-06-23 17:32:52,429 fail2ban                [3448]: ERROR   Failed during confi>
Jun 23 17:32:52 a-20250612-1519 fail2ban-server[3448]: 2025-06-23 17:32:52,436 fail2ban                [3448]: ERROR   Async configuration>
Jun 23 17:32:52 a-20250612-1519 systemd[1]: fail2ban.service: Main process exited, code=exited, status=255/EXCEPTION
Jun 23 17:32:52 a-20250612-1519 systemd[1]: fail2ban.service: Failed with result 'exit-code'.

使用fail2ban-client内置客户端检查配置文件

root@a-20250612-1519:/etc/fail2ban# fail2ban-client -t
2025-06-27 09:47:45,235 fail2ban                [2664]: ERROR   Failed during configuration: Have not found any log file for sshd jail
2025-06-27 09:47:45,236 fail2ban                [2664]: ERROR   ERROR: test configuration failed

rsyslog​ 是 Linux/Unix 系统中最常用的 日志管理工具,用于收集、处理、过滤和转发系统日志,Ubuntu 20.04 Minimal没有安装rsyslog,无sshd日志,而fail2ban是基于日志实现的,导致启动失败,解决办法:安装rsyslog应用

sudo apt install -y rsyslog

https://unix.stackexchange.com/questions/108241/debian-auth-log-missing-from-var-log

Logo

分享最新的 NVIDIA AI Software 资源以及活动/会议信息,精选收录AI相关技术内容,欢迎大家加入社区并参与讨论。

更多推荐