返回社区案例

将 fail2ban 的 banaction 从 iptables-multiport 改为 iptables

发布时间:2026/7/2浏览量:246

【最近实战】

我通过 Wisdom SSH 连接到服务器后,先执行了 systemctl enable fail2ban && systemctl start fail2ban && systemctl status fail2ban 来启用并启动 fail2ban 服务。AI 助手执行后返回了服务状态,显示 fail2ban 已成功启用并运行,主进程 PID 为 14401,状态为 active (running)。

接着我提出需求:把 fail2ban 的防火墙改成 iptables。AI 助手先尝试读取 /etc/fail2ban/jail.local,发现文件不存在,于是转而读取 /etc/fail2ban/jail.conf,在其中找到了关键配置行:

banaction = iptables-multiport
banaction_allports = iptables-allports

当前默认的 banaction 是 iptables-multiport,需要改为 iptables。AI 助手遵循 fail2ban 的最佳实践——不直接修改 jail.conf(因为升级会覆盖),而是创建 jail.local 来覆盖配置。它在 /etc/fail2ban/jail.local 中写入了:

[DEFAULT]
banaction = iptables

随后 AI 助手执行 systemctl restart fail2ban && systemctl status fail2ban 重启服务,返回结果显示 fail2ban 已重新启动,主进程 PID 变为 1500,状态正常。

整个操作通过 Wisdom SSH 的 AI 辅助功能完成,从分析现有配置、确定修改方案到执行重启,一气呵成。现在 fail2ban 的封禁动作会使用 iptables 而非 iptables-multiport 来执行封禁。

本文由用户分享,展示了Wisdom SSH在AI运维中的实际应用

推荐社区案例

点击阅读真实AI运维案例