Why Tunnel?
- No open inbound ports — your server initiates the outbound connection
- Automatic TLS (HTTPS) on your custom domain
- Cloudflare WAF and DDoS protection included
- Works behind CGNAT, VPNs, and strict corporate firewalls
- Free for personal and small-team use
Prerequisites
- A domain on Cloudflare DNS (free account is fine)
- OpenClaw running locally on port
18789 cloudflaredCLI installed (see Step 1)
Step 1 — Install cloudflared
# Download and install
curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 \
-o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared
# Verify
cloudflared --versioncurl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg \
| tee /usr/share/keyrings/cloudflare-main.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main" \
| tee /etc/apt/sources.list.d/cloudflared.list
apt update && apt install cloudflared -yStep 2 — Quick Test (no domain needed)
Before setting up a named tunnel, verify the connection with a temporary URL:
cloudflared tunnel --url http://127.0.0.1:18789 --no-autoupdate
# Output: Your quick Tunnel has been created! Visit it at:
# https://random-words-here.trycloudflare.comUse this temporary URL to test webhook integrations (Feishu, WeCom, DingTalk) before committing to a permanent setup.
Step 3 — Create a Named Tunnel (Permanent)
# Log in (opens browser for Cloudflare auth)
cloudflared tunnel login
# Create a named tunnel
cloudflared tunnel create openclaw-gateway
# Outputs: Tunnel ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# Create config file
mkdir -p ~/.cloudflared
cat > ~/.cloudflared/config.yml << 'EOF'
tunnel: openclaw-gateway
credentials-file: /root/.cloudflared/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json
ingress:
- hostname: gateway.your-domain.com
service: http://127.0.0.1:18789
- service: http_status:404
EOFStep 4 — Route DNS
# Create CNAME record pointing to your tunnel
cloudflared tunnel route dns openclaw-gateway gateway.your-domain.com
# Test the tunnel (foreground — Ctrl+C to stop)
cloudflared tunnel run openclaw-gateway
# Verify it's accessible
curl https://gateway.your-domain.com/statusStep 5 — Run as systemd Service
# Install as system service
cloudflared service install
# Enable and start
systemctl enable cloudflared
systemctl start cloudflared
# Check status
systemctl status cloudflared
journalctl -u cloudflared -f --no-pager -n 30Step 6 — Multiple Services on One Tunnel
You can expose multiple local services through a single tunnel using hostname routing:
tunnel: openclaw-gateway
credentials-file: /root/.cloudflared/YOUR-TUNNEL-ID.json
ingress:
# OpenClaw gateway
- hostname: gateway.your-domain.com
service: http://127.0.0.1:18789
# OpenClaw Codex site (if self-hosted)
- hostname: codex.your-domain.com
service: http://127.0.0.1:8443
# Catch-all
- service: http_status:404Troubleshooting
| Problem | Fix |
|---|---|
ERR_TOO_MANY_REDIRECTS | Set SSL mode to "Full" in Cloudflare dashboard → SSL/TLS |
| Tunnel offline after reboot | Run systemctl enable cloudflared |
| WebSocket drops after 100s | Enable "WebSockets" in Cloudflare dashboard → Network |
| High latency | Check Cloudflare datacenter routing; consider a VPS in closer region |
What's Next?
- Connect to Feishu — now that you have a public URL
- Connect to WeCom — webhook setup
- Security Hardening — add Cloudflare Access for admin routes