openclaw允许公网和内网访问的实现

Written by

in

文章目录
  • OpenClaw 网关默认只监听 127.0.0.1:18789(本地回环地址),导致无法通过公网 IP 访问。
  • 请尝试访问:http://xxx.xx.xx.xx:18789  # 给你分配的公网IP
  • 命令 用途 openclaw gateway status 查看网关运行状态 openclaw gateway start/stop/restart 启动/停止/重启网关 openclaw config get gateway 查看网关配置 openclaw config set gateway.bind “lan” 设置监听模式为公网可访问 openclaw config set gateway.port 8080 修改监听端口 openclaw doctor 诊断配置问题 openclaw logs –follow 实时查看日志
  • 目录
    • 🔍 问题原因
    • 🛠️ 排查与修复过程
      • 步骤 1:检查防火墙规则
      • 步骤 2:检查 OpenClaw 服务状态
      • 步骤 3:查看当前网关配置
      • 步骤 4:修改配置允许公网访问
    • ✅ 现在可以访问了
      • 📚 相关命令速查表
        • gateway.bind 模式说明

      OpenClaw 网关默认只监听 127.0.0.1:18789(本地回环地址),导致无法通过公网 IP 访问。

      # 查看防火墙是否放行 18789 端口
      openclaw 网关状态检查(通过腾讯云 API 查询)

      结果:防火墙已放行 18789 端口 ✅

      openclaw gateway status
      

      发现:服务运行中,但监听地址是 127.0.0.1:18789(仅本地)

      openclaw config get gateway
      

      输出

      {
        "port": 18789,
        "mode": "local",
        "bind": "loopback",  // ← 问题在这里
        "controlUi": { ... },
        "auth": { ... }
      }

      # 将 bind 模式从 loopback 改为 lan(局域网/公网可访问)
      openclaw config set gateway.bind "lan"
      
      # 重启网关服务
      openclaw gateway restart
      

      成功提示

      Config overwrite: /root/.openclaw/openclaw.json
      Updated gateway.bind. Restart the gateway to apply.
      Restarted systemd service: openclaw-gateway.service

      请尝试访问:http://xxx.xx.xx.xx:18789  # 给你分配的公网IP

      命令 用途
      openclaw gateway status 查看网关运行状态
      openclaw gateway start/stop/restart 启动/停止/重启网关
      openclaw config get gateway 查看网关配置
      openclaw config set gateway.bind “lan” 设置监听模式为公网可访问
      openclaw config set gateway.port 8080 修改监听端口
      openclaw doctor 诊断配置问题
      openclaw logs –follow 实时查看日志

      模式 说明
      loopback 仅本地访问(127.0.0.1)
      lan 局域网/公网可访问(0.0.0.0)
      tailnet 通过 Tailscale 网络访问
      auto 自动选择
      custom 自定义配置

      现在您应该可以通过浏览器正常访问 OpenClaw 的 Web 界面了!

      到此这篇关于openclaw允许公网和内网访问的实现的文章就介绍到这了,更多相关openclaw公网和内网访问内容请搜索风君子博客以前的文章或继续浏览下面的相关文章,希望大家以后多多支持风君子博客!

      站内搜索