惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - Nihaorz

告别闪烁,拥抱流畅:在 Windows Terminal 中完美配置 Cygwin 环境 Nginx 透明代理 + 自动回源存储:访问即缓存,落盘即文件 创建 docker ipvlan,让 docke 容器获取独立ip 电犀牛 R68s iStoreOS 2.5G 网口速率优化 解决 openwrt ssh 命令行终端 home、end 键不可用问题 一键添加视频封面脚本 ffmpeg 转码参数 docker save 远程 ssh 主机直接 load,不产生本地文件 AutoHotKey 脚本 - win10 自动连接无线显示器 SSH 登录/退出实时监控脚本 OpenClaw 安装部署,配置 deepseek curl 断点续传下载 debian iso 镜像下载地址 linux 安装 zerotier,加入网络 ssh 配置密钥登录,关闭密码登录 memc - 基于 shell 的交互式清理内存脚本 基于 Fail2ban 的 OpenWRT SSH 入侵自动反制方案 Linux Screen 命令速查 使用 ofelia 在 docker 容器中执行计划任务 linux 磁盘挂载示例
基于 Fail2ban 的 SSH 入侵自动反制方案
Nihaorz · 2026-03-04 · via 博客园 - Nihaorz

安装配置脚本(ssh 端口和 ignoreip 自行修改):

# 创建 auth.log(防止文件不存在时,fail2ban 启动报错)
touch /var/log/auth.log

# 安装 rsyslog、fail2ban 和 nftables
apt update
apt install rsyslog fail2ban nftables -y
systemctl enable rsyslog
systemctl enable fail2ban
systemctl enable nftables

# 编写 jail.local
tee /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
# 基础封禁参数
bantime = 7200
findtime = 600
maxretry = 5

# 递进式封禁设置
bantime.increment = true
bantime.factor = 2
bantime.max = -1

# 惯犯快速通道
recidive.threshold = 3
recidive.bantime = -1

# 网络层配置
banaction = nftables-multiport
chain = input

# 白名单(务必添加你的管理IP!)
ignoreip = 127.0.0.1/8 ::1 192.168.100.0/24 192.168.1.0/24

[sshd]
# SSH服务保护配置
enabled = true
port = 22
filter = sshd
logpath = /var/log/auth.log
EOF

# 重启 fail2ban
systemctl restart fail2ban

常用指令:

# 查看 fail2ban 运行状态
systemctl status fail2ban

# 查看封禁 IP 列表
fail2ban-client status sshd

# 手动封禁指定 IP
fail2ban-client set sshd banip 111.183.145.241

# 解封指定 IP
fail2ban-client set sshd unbanip 111.183.145.241

# 解封所有 IP
fail2ban-client unban --all

# 查看 fail2ban 日志
tail -f /var/log/fail2ban.log

# 重启 fail2ban
systemctl restart fail2ban

# 查看登录失败日志
tail -f /var/log/auth.log | egrep --color=auto "Failed (password|publickey)|invalid user|Connection (closed|refused)|authentication failure|not allowed"

清理并查看最新日志:

> /var/log/fail2ban.log
> /var/log/auth.log
fail2ban-client unban --all
systemctl restart fail2ban
sleep 2
fail2ban-client status sshd

OpenWrt 版参考这个:https://www.cnblogs.com/nihaorz/p/19660788