📋 OpenClaw 节点配对配置指南
我总结下来最好在局域网使用,除非是网络高手,能屏蔽安全问题,因为使用了ssh 隧道。
一、网关主机配置 (Gateway Host)
1. 启动 Gateway 服务
首先确保网关正在运行:
# 检查状态
openclaw status
openclaw gateway status
# 查看日志
openclaw logs --follow
2. 确认 Gateway 绑定的地址
默认情况下,Gateway 绑定到 loopback (127.0.0.1):
让 OpenClaw 在局域网内通过 HTTPS 正常访问的完整配置 - 掘金 ,这个可以有也可以没有,根据需要处理,不影响节点配对
二、节点主机配置 (Node Host)
远程 SSH 隧道连接 (跨网络)
这是你遇到的场景,网关在远程主机上。
步骤 1: 建立 SSH 隧道
在节点主机(你的电脑)上:
# 保持此命令运行,将本地端口 18790 映射到远程网关的 127.0.0.1:18789
ssh -N -L 18790:127.0.0.1:18789 user@你的 VPS 或服务器 IP
步骤 2: 配置环境变量
获取网关 token:
# 在网关主机上执行
openclaw dashboard
# 执行后返回的链接带着 token
Dashboard URL: http://127.0.0.1:18789/#token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
然后在节点主机上设置:
# Linux
export OPENCLAW_GATEWAY_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# window
$env:OPENCLAW_GATEWAY_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
步骤 3: 启动节点客户端
通过隧道连接(保持和前一步相同的窗口):
openclaw node run --host 127.0.0.1 --port 18790 --display-name "远程节点"
步骤 4: 在网关主机批准配对
回到网关主机,查看待批准的配对请求(我的不知道为什么直接就配对好了):
# 查看所有设备配对请求
openclaw devices list
# 批准节点 (用 request ID)
openclaw devices approve <requestId>
# 或拒绝
openclaw devices reject <requestId>
步骤 5: 验证连接状态
# 在网关主机上查看节点列表
openclaw nodes status
# 查看节点详情
openclaw nodes describe --node <idOrNameOrIp>
三、节点主机配置执行权限
节点配对后,需要设置命令白名单:
# 在白名单中添加允许执行的命令
openclaw approvals allowlist add --node "节点名称" "/usr/bin/uname"
openclaw approvals allowlist add --node "节点名称" "/bin/bash"
# 检查现有权限
openclaw approvals get --node "节点名称"
✅四、 SSH 反向隧道
成功原因:
正确流程:
节点主机 → SSH 主动连接 → 远程网关服务器 → 复用通道双向通信 ✅ 成功
(出站连接允许) (中转点) (数据可以返回)
优势:
- TCP NAT 对出站连接放行
- 防火墙通常允许 SSH(端口 22)
- 一旦隧道建立,双向数据传输可用
- 无需公网 IP、无需开放入站端口
五、配置总结对比表
| 方案 | 可行性 | 要求 | 风险 |
|---|---|---|---|
| SSH 反向隧道 | ✅ 推荐 | 有中转服务器 + SSH 可达 | 低 |
六、常见错误排查
# 检查节点状态
openclaw nodes status
# 查看节点详情和权限
openclaw nodes describe --node <节点名>
# 日志实时跟踪
openclaw logs --follow
# 重新批准设备配对
openclaw devices list
总结:SSH 反向隧道是目前最安全、稳定的方案,因为它:
- 利用出站连接(防火墙默认允许)
- 无需暴露网关到公网
- 不依赖公网 IP
- 加密传输