CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

cloudflared

$ cloudflared 官方出品 高风险
Cloudflare · 浏览器与网页抓取 · Apache-2.0 · macos / linux / windows

cloudflared 用于将本地服务接入 Cloudflare Tunnel(tunnel)、查询隧道状态(tunnel list --output json),以及为非浏览器客户端获取 Cloudflare Access 令牌(access token)。快速隧道(--url)会作为长期前台守护进程运行。

FCRS-1.0 综合评分
82 /100
良好 (Good)
高置信度 (实测)
零摩擦安装命令
brew install cloudflared
CLI vs MCP 选型建议 仅 CLI 可用

管理 Cloudflare Tunnel 路由与获取 Access 令牌(cloudflared access token)必须使用该本地客户端,暂无 MCP 替代品。

Agent 友好度体检单

本地探针实测证据
✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
— 自省/Schema 发现
— 官方 SKILL.md
实测版本
cloudflared version 2025.6.1 (built 2025-06-17T09:42:18Z)
冷启动耗时
101 ms
退出码 (help / 非法参数)
0 / 0
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
NAME:
   cloudflared - Cloudflare's command-line tool and agent

USAGE:
   cloudflared [global options] [command] [command options]

VERSION:
   2025.6.1 (built 2025-06-17T09:42:18Z)

DESCRIPTION:
   cloudflared connects your machine or user identity to Cloudflare's global network.
     You can use it to authenticate a session to reach an API behind Access, route web traffic to this machine,
     and configure access control.
   
     See https://developers.cloudflare.com/cloudflare-one/connections/connect-apps for more in-depth documentation.

COMMANDS:
   update     Update the agent if a new version exists
   version    Print the version
   proxy-dns  Run a DNS over HTTPS proxy server.
   tail       Stream logs from a remote cloudflared
   service    Manages the cloudflared launch agent
   help, h    Shows a list of commands or help for one command
   Access:
     access, forward  access <subcommand>
   Tunnel:
     tunnel  Use Cloudflare Tunnel to expose private services to the Internet or to Cloudflare connected private users.

GLOBAL OPTIONS:
   --output value                               Output format for the logs (default, json) (default: "default") [$TUNNEL_MANAGEMENT_OUTPUT, $TUNNEL_LOG_OUTPUT]
   --credentials-file value, --cred-file value  Filepath at which to read/write the tunnel credentials [$TUNNEL_CRED_FILE]
   --region value                               Cloudflare Edge region to connect to. Omit or set to empty to connect to the global region. [$TUNNEL_REGION]
   --edge-ip-version value                      Cloudflare Edge IP address version to connect with. {4, 6, auto} (default: "4") [$TUNNEL_EDGE_IP_VERSION]
   --edge-bind-address value                    Bind to IP address for outgoing connections to Cloudflare Edge. [$TUNNEL_EDGE_BIND_ADDRESS]
   --label value                                Use this option to give a meaningful label to a specific connector. When a tunnel starts up, a connector id unique to the tunnel is generated. This is a uuid. To make it easier to identify a connector, we will use the hostname of the machine the tunnel is running on along with the connector ID. This option exists if one wants to have more control over what their individual connectors are called.
   --post-quantum, --pq                         When given creates an experimental post-quantum secure tunnel (default: false) [$TUNNEL_POST_QUANTUM]
   --management-diagnostics                     Enables the in-depth diagnostic routes to be made availab

FCRS-1.0 六维评分拆解

Agent 友好度 20 / 25

在 tunnel list/info 上支持 --output json、提供 --no-autoupdate 与可脚本化的 access token,但 tunnel run 为长期阻塞守护进程。

  • Supports --output json on management commands and access token
安全与权限边界 16 / 25

通过公网 trycloudflare.com 暴露本地服务会绕过本地防火墙;在 ~/.cloudflared/ 下保存 cert.pem 与隧道凭据。

  • Publicly exposes localhost ports; stores ~/.cloudflared/cert.pem
安装与运行摩擦 14 / 15

静态 Go 单二进制,支持 brew、apt/rpm、Docker 与 GitHub Releases 安装。

  • Single static Go binary across macOS, Linux, Windows
能力覆盖与边际价值 13 / 15

非常适合本地 Webhook 联调、预览分享以及在脚本中穿透 Cloudflare Access 鉴权。

  • Zero-cost quick tunnels and Cloudflare Access CLI token helpers
维护与来源背书 10 / 10

Cloudflare 官方开源项目(cloudflare/cloudflared),Apache-2.0 协议。

  • Official cloudflare/cloudflared repository
文档与可验证性 9 / 10

developers.cloudflare.com 文档与 --help 说明极其完善。

  • Official docs at developers.cloudflare.com

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 浏览器 OAuth 服务账号密钥 本地配置文件
凭证存储位置

在 ~/.cloudflared/ 目录保存源证书(cert.pem)与隧道凭据 JSON;Access 令牌按应用域名缓存在本地。

潜在副作用
只读查询 本地写入 远端写入
费用与配额提示

免费开源(Apache-2.0 协议)Go 二进制;Cloudflare Zero Trust 免费版即可使用基础隧道。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# cloudflared Agent Rules
- Never run `cloudflared tunnel --url` unattended without user approval—it exposes localhost services to the public internet.
- Pass `--no-autoupdate` in CI/agent runs and terminate background tunnel processes explicitly when finished.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 列出已配置的 Cloudflare 隧道
cloudflared tunnel list --output json

向 Cloudflare API 查询活跃隧道并输出结构化 JSON(--output json)。

获取已缓存的 Cloudflare Access JWT 供 curl 使用
cloudflared access token -app=https://internal.example.com

打印 Access JWT 令牌,方便 Shell 脚本注入 cf-access-token 请求头。

受控写入与预演

为本地端口启动临时公网隧道
cloudflared tunnel --url http://localhost:3000 --no-autoupdate

将本地 3000 端口映射到临时 trycloudflare.com 公网地址,直至手动终止。

核心优势

  • + 管理子命令原生支持 --output json 输出。
  • + 单文件静态 Go 二进制,快速 --url 隧道无需登录账号即可启动。

注意事项与踩坑点

  • ! 启动快速隧道会直接将 localhost 服务暴露到公网。
  • ! 隧道运行命令会作为前台守护进程持续阻塞。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI