云服务器 + WireGuard
与 Tailscale 方案一样,网关不会在公网上监听:它只监听服务器的 WireGuard 地址,iPhone 通过隧道访问它。区别在于隧道由你自己运行,不依赖第三方协调服务。服务器只为 WireGuard 开放一个 UDP 端口,不为 hmob 开放任何端口。
示例使用以下地址,请替换为你自己的地址:
| 地址 | |
|---|---|
| WireGuard 网络 | 10.8.0.0/24 |
| 服务器(WireGuard 端点) | 10.8.0.1,监听 UDP 51820 |
| iPhone | 10.8.0.2 |
- 一台 Linux 服务器(x86_64 或 aarch64),已安装 herdr,有 root 权限,并已安装
wireguard-tools、nftables和qrencode(例如sudo apt install wireguard-tools nftables qrencode)。 - iPhone 上已安装官方 WireGuard App 和 Hmob App。
1. 服务器:WireGuard 端点
Section titled “1. 服务器:WireGuard 端点”为服务器和手机生成密钥:
sudo sh -c 'umask 077; cd /etc/wireguard && wg genkey | tee server.key | wg pubkey > server.pub && wg genkey | tee phone.key | wg pubkey > phone.pub'创建 /etc/wireguard/hmobwg.conf:
[Interface]Address = 10.8.0.1/32ListenPort = 51820PostUp = wg set %i private-key /etc/wireguard/server.keyPreUp = nft -f /etc/wireguard/hmobwg.nftPostDown = nft delete table inet hmobwg
[Peer]# iPhone: the contents of /etc/wireguard/phone.pubPublicKey = <phone public key>AllowedIPs = 10.8.0.2/322. 服务器:只允许手机访问 hmob
Section titled “2. 服务器:只允许手机访问 hmob”默认情况下,WireGuard 对端可以访问服务器上的所有服务。只放行 hmob,丢弃来自隧道的其他所有流量。创建 /etc/wireguard/hmobwg.nft:
table inet hmobwg { chain input { type filter hook input priority filter - 5; policy accept; iifname "hmobwg" ip saddr 10.8.0.2 ip daddr 10.8.0.1 tcp dport 8443 accept comment "hmob" iifname "hmobwg" drop }}启动隧道:
sudo systemctl enable --now wg-quick@hmobwgsudo wg show hmobwg在云防火墙或安全组中放行入站 UDP 51820(如果可以,将来源限制为你使用的网络)。不要开放 TCP 8443。
3. 手机:导入隧道
Section titled “3. 手机:导入隧道”在服务器上生成手机的配置,并以二维码形式显示:
SERVER_PUBLIC_IP=203.0.113.10 # 服务器的公网地址sudo sh -c "umask 077; cat > /etc/wireguard/phone.conf" <<EOF[Interface]PrivateKey = $(sudo cat /etc/wireguard/phone.key)Address = 10.8.0.2/32
[Peer]PublicKey = $(sudo cat /etc/wireguard/server.pub)Endpoint = $SERVER_PUBLIC_IP:51820AllowedIPs = 10.8.0.1/32PersistentKeepalive = 25EOFsudo qrencode -t ansiutf8 < /etc/wireguard/phone.conf在 WireGuard App 中点击 + → 通过二维码创建,扫描二维码并打开隧道。然后从服务器上删除手机的密钥材料:
sudo rm /etc/wireguard/phone.conf /etc/wireguard/phone.keyAllowedIPs = 10.8.0.1/32 只让发往服务器的流量走隧道,手机的其他流量不受影响。
4. 服务器:安装网关
Section titled “4. 服务器:安装网关”以运行 herdr 的用户(而非 root)执行:
curl -fsSL https://hmob-app.github.io/install.sh | shexport PATH="$HOME/.local/bin:$PATH" # 如果脚本提示它不在 PATH 中hmob install-service --bind 10.8.0.1ss -ltn | grep 8443 # 只有 10.8.0.1:8443这会安装一个 systemd 用户服务并启用 lingering,因此无需登录即可开机运行。
5. 配对 iPhone
Section titled “5. 配对 iPhone”hmob pair --url https://10.8.0.1:8443打开 WireGuard 隧道后,打开 Hmob App,点击 扫描配对二维码 并扫描二维码。请始终通过扫码配对:手动输入不包含证书指纹,在网关的自签名证书下会失败。
基于规则的 VPN 客户端(Stash、Clash 等)
Section titled “基于规则的 VPN 客户端(Stash、Clash 等)”基于规则的客户端默认会让 10.0.0.0/8 等私有地址段绕过隧道,因此连接 10.8.0.1 会超时。请改用私有主机名:
- 选择以
.test或.internal结尾的名称,例如hmob.wg.test。App 仅对这些保留后缀放宽 iOS 的系统信任检查,是否信任仍由二维码中的指纹决定。 - 在服务器的 WireGuard 地址上运行一个小型 DNS 服务器,将该名称解析为
10.8.0.1,其他查询全部转发(例如dnsmasq --host-record=hmob.wg.test,10.8.0.1 --listen-address=10.8.0.1 --bind-interfaces --server=1.1.1.1),并在hmobwg.nft的 drop 规则之前放行来自手机的 TCP/UDP 53。 - 在客户端中使用 fake-ip DNS,将 WireGuard 出站的
dns设为10.8.0.1,并把DOMAIN,hmob.wg.test,<your WireGuard outbound>放在所有局域网直连规则之前。 - 用
hmob pair --url https://hmob.wg.test:8443配对。
| 现象 | 检查项 |
|---|---|
| 配对超时 | WireGuard App 中隧道已打开,且 sudo wg show hmobwg 显示最近有握手;UDP 51820 已开放;sudo tcpdump -ni hmobwg port 8443 能看到数据包。 |
| 数据包到达但无法连接 | 运行 sudo nft list table inet hmobwg:accept 规则位于 drop 规则之前;ss -ltn 显示 hmob 在 10.8.0.1:8443 上监听。 |
| “A TLS error caused the secure connection to fail” | 你手动输入了地址,或使用了不以 .test / .internal 结尾的主机名。请重新扫码配对。 |
| 大屏幕内容卡住 | 将隧道 MTU 降到 1280–1380(在手机配置的 [Interface] 中设置 MTU = 1380)。 |