跳转到内容

Mac + Tailscale

你的 Mac 运行 herdr 和 hmob 网关。iPhone 通过你的 tailnet 访问网关,因此不会向局域网或互联网暴露任何内容。

  • 一台 Apple 芯片的 Mac,已安装 herdr。
  • 在 Mac 和 iPhone 上都安装 Tailscale,并登录同一个 tailnet。
  • iPhone 上已安装 Hmob App。
终端窗口
curl -fsSL https://hmob-app.github.io/install.sh | sh

如果脚本提示 ~/.local/bin 不在 PATH 中,请将其加入(以 zsh 为例):

终端窗口
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && exec zsh

macOS 版 Tailscale App 的命令行工具位于 App 包内:

终端窗口
TS=/Applications/Tailscale.app/Contents/MacOS/Tailscale
command -v tailscale >/dev/null && TS=tailscale
TS_IP="$("$TS" ip -4)"
echo "$TS_IP" # 100.x.y.z

只在 Tailscale 地址上监听:

终端窗口
hmob install-service --bind "$TS_IP"
hmob status

这会安装一个 launchd agent,在登录时启动,停止后自动重启。日志写入 ~/Library/Logs/。

终端窗口
hmob pair --url "https://$TS_IP:8443"

在 iPhone 上打开 Tailscale,然后打开 Hmob App,点击 扫描配对二维码,扫描终端中显示的二维码。该二维码有效期 5 分钟,只能使用一次。

只有在 Mac 处于唤醒且在线状态时,iPhone 才能访问网关。对于长时间运行的 agent 任务,请在接通电源时阻止睡眠(系统设置 → 电池 → 选项,台式 Mac 为 节能),或在终端中运行 caffeinate -s。

现象 检查项
配对超时 iPhone 上已打开 Tailscale;hmob status 显示服务正在运行;"$TS" ping <iphone-name> 能连通手机。
“A TLS error caused the secure connection to fail” 你手动输入了地址,或通过主机名配对。请重新扫描用 --url https://$TS_IP:8443 生成的二维码进行配对。
终端打开的是普通 shell 找不到 herdr。安装 herdr 后重新安装服务:hmob install-service --bind "$TS_IP"。