From dcbaa1b41d3cc184537f0f7ecdfe1134c5390eb7 Mon Sep 17 00:00:00 2001 From: timmy Date: Sat, 18 Apr 2026 23:02:27 +0800 Subject: [PATCH] docs: add NetBird as SSH whitelist alternative + StrongHotpink-VM case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit External VM 141.11.93.252 had SSH locked to specific source IPs (tailscale0, HiNet WAN, one other). Mac couldn't reach it from other ISPs. Solved by joining the VM to our NetBird mesh and adding an iptables ACCEPT rule for wt0:22. Run into the same Tailscale kernel-mode iptables-legacy collision already documented in peer-deployment-ops.md — systemd oneshot workaround fixed it. Doc now describes both the temporary ProxyJump solution and the permanent mesh-membership solution, plus a config strategy of retiring per-IP whitelists in favor of a single wt0 ACCEPT rule. --- ssh-access.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/ssh-access.md b/ssh-access.md index 7f85119..45b2f90 100644 --- a/ssh-access.md +++ b/ssh-access.md @@ -78,3 +78,67 @@ netbird ssh ct100.netbird.selfhosted - **Dashboard "SSH Access" disabled 跟你 SSH 得不得進去沒關係** — 前者是 NetBird 自己的通道功能,後者是你一般用的 SSH - 家用環境通常**不需要啟用** NetBird SSH,用原生 OpenSSH 就夠 - 有需要再開,兩種不衝突,可以並存 + +## 實務應用:用 NetBird 取代 SSH 源 IP 白名單 + +### 情境 + +遠端 VM 的 SSH (port 22) 被 iptables 白名單限制只有特定源 IP 能進: + +``` +ACCEPT tailscale0 * 0.0.0.0/0 tcp dpt:22 /* via Tailscale */ +ACCEPT * * 211.23.141.206 tcp dpt:22 /* specific IP */ +ACCEPT * * 125.229.110.50 tcp dpt:22 /* HiNet WAN */ +DROP * * 0.0.0.0/0 tcp dpt:22 /* drop everything else */ +``` + +你的 Mac 從咖啡店連不到,因為當下 ISP 出口 IP 不在白名單。 + +### 兩個解法對比 + +**A. 暫時跳板**(不改遠端 VM): + +``` +ssh -J root@.netbird.selfhosted root@141.11.93.252 +``` + +Mac → NetBird → 家裡有白名單的 peer → 借它的公網 IP → VM。原生 OpenSSH 的 `ProxyJump`,跟 NetBird 的 SSH Access 功能無關。 + +**B. 把 VM 加進 NetBird mesh**(長期治本): + +1. 在 VM 部署 NetBird client 容器(見 `peer-deployment-ops.md`) +2. 在 VM 的 iptables 加一條鏡像 tailscale0 的規則: + ``` + iptables -I INPUT <位置> -i wt0 -p tcp --dport 22 -j ACCEPT \ + -m comment --comment "Allow SSH from NetBird interface" + ``` + 插入點:在「DROP all other SSH」那條之前 +3. 之後 Mac / iPhone / 任何 NetBird peer 都能直接 SSH 到 VM,**不用再跳板** + +### 本部署的實例(StrongHotpink-VM,2026-04-18) + +`141.11.93.252` 這台 VM 原本 SSH port 22 只認 `tailscale0` + `211.23.141.206` + HiNet。Mac 從另一個 ISP 連不到。採用方案 B: + +- NetBird IP `100.71.121.88`,FQDN `stronghotpink-vm.netbird.selfhosted` +- 加 `iptables -I INPUT <位置> -i wt0 -p tcp --dport 22 -j ACCEPT` +- 踩到同一個 **Tailscale kernel-mode iptables-legacy 衝突**(見 `peer-deployment-ops.md`),加 systemd oneshot 解決 +- `auto_groups=[servers]` 直接進正確 group,policy 自動套用 + +結果:Mac 直接 `ssh root@stronghotpink-vm.netbird.selfhosted` 即可進入,RTT ~175ms(走 Relay,跨區 P2P 不易打通但不影響 SSH)。 + +### 配置策略建議 + +遠端 VM 的 SSH 白名單**保留 NetBird interface 這條**、**砍掉固定 IP 白名單**: + +```diff + ACCEPT tailscale0 * tcp dpt:22 ++ ACCEPT wt0 * tcp dpt:22 +- ACCEPT * * 211.23.141.206 tcp dpt:22 ← 砍掉 +- ACCEPT * * 125.229.110.50 tcp dpt:22 ← 砍掉 + DROP * * 0.0.0.0/0 tcp dpt:22 +``` + +好處: +- 不用再維護公網 IP 白名單(HiNet 動態 IP 變了就斷線) +- SSH 強制走 overlay 網路,減少暴露面 +- 新加入的 NetBird peer(增加新裝置)自動取得存取權,不用改防火牆