以下是完整的排查和解决过程,以及您学习的命令参考:


🔍 问题原因

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


🛠️ 排查与修复过程

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

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

步骤 2:检查 OpenClaw 服务状态
openclaw gateway status

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

步骤 3:查看当前网关配置
openclaw config get gateway

输出

{
  "port": 18789,
  "mode": "local",
  "bind": "loopback",  // ← 问题在这里
  "controlUi": { ... },
  "auth": { ... }
}
步骤 4:修改配置允许公网访问
# 将 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 实时查看日志
gateway.bind 模式说明
模式 说明
loopback 仅本地访问(127.0.0.1)
lan 局域网/公网可访问(0.0.0.0)
tailnet 通过 Tailscale 网络访问
auto 自动选择
custom 自定义配置

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

转至:https://cloud.tencent.com/developer/article/2635958

Logo

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐