Files

40 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# MyBlog IP 白名单自动更新(家庭端)
## 这是什么
家庭宽带的公网 IP 会不定期变化。阿里云安全组 22 端口如果只放行固定 IP,
换 IP 后你就会被自己挡在门外。
这套方案让家庭电脑定时检测自己的公网 IP,一旦变化就通知服务器,
服务器自动调用阿里云 API 把安全组 22 端口白名单更新为最新 IP。
流程:
1. report.ps1 请求 博客/myip 获取当前公网 IP
2. 与上次记录比较,有变化时 POST /api/ipwatch/report
3. 服务器调用阿里云 API 更新安全组(先加新规则、后删旧规则)
## 家庭端配置步骤(Windows
1. 复制 ipwatch.conf.example 为 ipwatch.conf,填写:
- SERVER:博客地址(默认 https://guzhujushi.cn
- SECRET:与服务器 .env 中 IPWATCH_SECRET 相同
2. 运行安装脚本(注册每 30 分钟的计划任务并立即执行一次):
powershell -ExecutionPolicy Bypass -File .\install.ps1
3. 查看日志确认成功:
Get-Content .\ipwatch.log
正常会看到:白名单更新成功:你的公网IP(服务器:白名单更新成功)
或:公网 IP 未变化:xxx(表示无需更新,正常)。
## 手动运行 / 卸载
powershell -ExecutionPolicy Bypass -File .\report.ps1
powershell -ExecutionPolicy Bypass -File .\uninstall.ps1
## 安全说明
- 家庭端只保存 IPWATCH_SECRET(随机字符串);阿里云 AccessKey 只存在服务器
.env 中,不要复制到家庭端或提交到 git。
- 如果 IPWATCH_SECRET 泄露:登录服务器改 .env 里的值,再同步修改本目录
ipwatch.conf,最后重启后端服务即可。
- 服务器端每次上报限流 60 秒一次,且只增删 22 端口 /32 单 IP 规则。