Files
nas/scripts/fix-mihomo-tailscale.sh
T
wangjia 3fc6b402cd 新增 Tailscale 公网访问方案并落地
- 调研对比 Tailscale / Cloudflare Tunnel / frp / QuickConnect,
  自用+大文件+隐藏IP 场景下选定 Tailscale(避开 CF 免费版 100MB 上限)
- NAS 已上线 tailnet(ds925 / 100.95.151.13),Gitea 与 Synology Photos
  公网访问已验证(含 >100MB 视频上传)
- 修复关键坑:mihomo fake-ip 劫持 Tailscale 控制面域名导致 tailscale up
  卡住,在 fake-ip-filter 加入 +.tailscale.com 等并提供修复脚本
- 文档:docs/public-access.md(部署/踩坑/验证)
- 可选件:docker/derp(自建 DERP 中继)
- 同步更新 CLAUDE.md(修正 git 公网地址、新增公网访问小节、端口、TODO)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 21:17:46 +08:00

53 lines
1.7 KiB
Bash
Raw 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.
#!/bin/sh
# 让 Tailscale 域名在 mihomo 里解析为真实 IP(绕开 fake-ip 劫持),
# 否则 tailscaled 连不上控制服务器、登录时拿不到 URL。
# 该脚本在 NAS 上运行;config.yaml 归 wangjia 所有,无需 root。
# 幂等:重复执行不会重复插入。改前自动备份,并热重载生效(不重启容器)。
set -e
CFG=/volume1/docker/proxy/mihomo/config.yaml
echo "==> 1/4 备份配置"
cp "$CFG" "$CFG.bak.tailscale"
echo " 备份: $CFG.bak.tailscale"
echo "==> 2/4 写入 fake-ip-filter(幂等)"
python3 - "$CFG" <<'PY'
import sys
p = sys.argv[1]
text = open(p).read()
if "+.tailscale.com" in text:
print(" 已存在,跳过插入")
sys.exit(0)
lines = text.splitlines(True)
add = [
" - '+.tailscale.com'\n",
" - '+.tailscale.io'\n",
" - '+.tailscale-dns.com'\n",
]
out, done = [], False
for ln in lines:
out.append(ln)
if (not done) and "+.pool.ntp.org" in ln:
out.extend(add)
done = True
if not done:
print(" !! 没找到锚点 '+.pool.ntp.org',未修改,请人工检查")
sys.exit(1)
open(p, "w").writelines(out)
print(" 已插入 3 条 tailscale 域名")
PY
echo "==> 3/4 热重载 mihomo"
curl -s -X PUT 'http://127.0.0.1:9090/configs?force=true' \
-H 'Content-Type: application/json' \
-d '{"path":"/root/.config/mihomo/config.yaml"}'
echo " reload 已请求"
echo "==> 4/4 验证解析(期望是真实公网 IP,不再是 198.18.x"
sleep 1
nslookup controlplane.tailscale.com 2>&1 | tail -3
echo "==> 完成。现在回到卡住的窗口按 Ctrl+C,重新执行:"
echo " sudo /var/packages/Tailscale/target/bin/tailscale up --reset --operator=wangjia"