<style>.toc-chapters{max-height:none!important}.copy-btn,#sidebar-toggle,#fullscreen-toggle{display:none!important}@media(max-width:768px){.tutorial-app{display:flex;height:auto;overflow:visible;flex-direction:column}.tutorial-main{order:0;overflow:visible}.tutorial-content{overflow:visible}.tutorial-sidebar{order:1;position:static!important;width:100%!important;min-width:0!important;max-height:none!important;display:flex!important;transform:none!important}.sidebar-toc{overflow:visible}}</style>

附录 C:Gateway 参数详解

Gateway(网关)是 OpenClaw 的核心——Agent 的大脑。所有消息、请求都通过它转发处理。理解 Gateway 参数,就是理解 OpenClaw 的命门。


🚪 端口 --port

Gateway 监听在哪个端口上。

# 用默认端口 (18789)
openclaw gateway start

# 指定端口
openclaw gateway start --port 19001

# 端口被占用时强制杀掉再起
openclaw gateway start --port 18789 --force

场景:在同一台机器上跑多个 OpenClaw 实例时,需要不同端口;或者 18789 已被其他程序占用。

也可以在 openclaw.json 中配置:

{
  "gateway": {
    "port": 18789
  }
}

🔗 绑定模式 --bind

控制 Gateway 监听在哪些网络接口上。

模式 含义 谁可以连
loopback 仅本机 只有你电脑上的程序可以连
lan 局域网 同一 WiFi/内网的其他设备可以连
tailnet Tailscale 网络 你的 Tailscale 网络内的设备可以连
auto 自动选择 OpenClaw 帮你选最合适的
custom 自定义 手动指定 IP 地址
# 只让本机访问(最安全)
openclaw gateway start --bind loopback

# 让局域网设备也能连
openclaw gateway start --bind lan

# 通过 Tailscale 远程访问
openclaw gateway start --bind tailnet

安全提醒--bind lan 会让局域网内其他人也能访问你的 Gateway。除非你清楚自己在做什么,否则建议用 loopbacktailnet

🎭 认证模式 --auth

谁可以连接你的 Gateway。

模式 说明 安全性
none 无认证,随便连 ❌ 仅调试用
token 令牌认证,需要共享密钥 ✅ 推荐
password 密码认证 ✅ 可选
trusted-proxy 信任代理,由上游代理验证 ✅ 高级部署
# 使用令牌认证(推荐)
openclaw gateway start --auth token --token "你的密令牌"

# 使用密码认证
openclaw gateway start --auth password --password "你的密码"

# 从文件读取密码
openclaw gateway start --auth password --password-file /路径/password.txt

如果设置了环境变量 OPENCLAW_GATEWAY_TOKEN--token 可以不传,自动用它。

🏠 模式 mode

openclaw.json 中的 gateway.mode 字段:

模式 说明
local 单机模式,一台电脑上用
remote 远程模式,供其他设备连接
edge 边缘节点模式

大部分用户用 local 就够了。

🦎 Tailscale 配置 --tailscale

通过 Tailscale 安全暴露 Gateway,免去公网暴露的风险。

# 关闭 Tailscale(默认)
openclaw gateway start --tailscale off

# 通过 Tailscale Serve 暴露
openclaw gateway start --tailscale serve

# 通过 Tailscale Funnel 暴露到公网
openclaw gateway start --tailscale funnel

# 退出时自动清理 Tailscale 配置
openclaw gateway start --tailscale serve --tailscale-reset-on-exit

区别:

  • Serve:只对你的 Tailscale 网络内的设备可见(用自己的设备组成的内网)
  • Funnel:暴露到公网,任何人都能访问(需要留意安全)
{
  "gateway": {
    "tailscale": {
      "mode": "serve",
      "resetOnExit": true
    }
  }
}

🔍 调试相关

# 前台运行(看实时日志)
openclaw gateway run

# 详细日志
openclaw gateway run --verbose

# 只显示 CLI 后端日志
openclaw gateway run --cli-backend-logs

# 精简 WebSocket 日志
openclaw gateway run --ws-log compact

# 记录模型流式输出到文件
openclaw gateway run --raw-stream --raw-stream-path ./stream.jsonl

📋 快速参考

# 最常用的启动方式
openclaw gateway start

# 开发调试
openclaw gateway run --verbose

# 远程访问(有 Tailscale)
openclaw gateway start --bind tailnet --auth token

# 远程访问(无 Tailscale,注意安全)
openclaw gateway start --bind lan --auth token

# 查看 Gateway 状态和连接性
openclaw gateway status

# 测试 Gateway 连通性
openclaw gateway probe

# 发现网络中的其他 Gateway
openclaw gateway discover

# 查看稳定性报告
openclaw gateway stability

# 查看用量统计
openclaw gateway usage-cost

💡 先用 openclaw gateway run 前台启动调试,稳定后再用 openclaw gateway start 后台运行。

系统教程,帮你把工具用好,再回到任务中。 浏览任务方案 →