openclaw

关注公众号 jb51net

关闭
AI > openclaw >

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

LuckyTHP

🔍 问题原因

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 界面了!

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