名称: cloudflare
描述: 连接 Cloudflare API 以管理 DNS、隧道和区域。当用户需要管理域名、DNS 记录或创建隧道时使用。
阅读时间:
- 用户询问 Cloudflare DNS 或域名
- 用户想要创建或管理 DNS 记录
- 用户需要设置 Cloudflare 隧道
- 用户想要列出其 Cloudflare 区域
元数据:
clawdbot:
emoji: "☁️"
requires:
bins: ["curl", "jq"]
连接 Cloudflare API,用于 DNS 管理、隧道和区域管理。
# 选项 A:存储在文件中(推荐)
echo "YOUR_API_TOKEN" > ~/.cloudflare_token
chmod 600 ~/.cloudflare_token
# 选项 B:环境变量
export CLOUDFLARE_API_TOKEN="YOUR_API_TOKEN"
./scripts/setup.sh
./scripts/zones/list.sh # 列出所有区域
./scripts/zones/list.sh --json # JSON 格式输出
./scripts/zones/get.sh example.com # 获取区域详情
# 列出记录
./scripts/dns/list.sh example.com
./scripts/dns/list.sh example.com --type A
./scripts/dns/list.sh example.com --name api
# 创建记录
./scripts/dns/create.sh example.com \
--type A \
--name api \
--content 1.2.3.4 \
--proxied
# 创建 CNAME 记录
./scripts/dns/create.sh example.com \
--type CNAME \
--name www \
--content example.com \
--proxied
# 更新记录
./scripts/dns/update.sh example.com \
--name api \
--type A \
--content 5.6.7.8
# 删除记录
./scripts/dns/delete.sh example.com --name api --type A
# 列出隧道
./scripts/tunnels/list.sh
# 创建隧道
./scripts/tunnels/create.sh my-tunnel
# 配置隧道入口规则
./scripts/tunnels/configure.sh my-tunnel \
--hostname app.example.com \
--service http://localhost:3000
# 获取运行令牌
./scripts/tunnels/token.sh my-tunnel
# 删除隧道
./scripts/tunnels/delete.sh my-tunnel
| 功能 | 所需权限 |
|---|---|
| 列出区域 | Zone:Read |
| 管理 DNS | DNS:Edit |
| 管理隧道 | Account:Cloudflare Tunnel:Edit |
创建令牌地址:dash.cloudflare.com/profile/api-tokens
./scripts/dns/create.sh mysite.com --type A --name api --content 1.2.3.4 --proxied
# 1. 创建隧道
./scripts/tunnels/create.sh webhook-tunnel
# 2. 配置入口规则
./scripts/tunnels/configure.sh webhook-tunnel \
--hostname hook.mysite.com \
--service http://localhost:8080
# 3. 添加 DNS 记录
TUNNEL_ID=$(./scripts/tunnels/list.sh --name webhook-tunnel --quiet)
./scripts/dns/create.sh mysite.com \
--type CNAME \
--name hook \
--content ${TUNNEL_ID}.cfargotunnel.com \
--proxied
# 4. 运行隧道
TOKEN=$(./scripts/tunnels/token.sh webhook-tunnel)
cloudflared tunnel run --token $TOKEN
| 标志 | 描述 |
|---|---|
--json |
API 原始 JSON 数据 |
--table |
格式化表格(默认) |
--quiet |
最小化输出(仅 ID) |
| 错误 | 解决方案 |
|---|---|
| "未找到 API 令牌" | 运行设置或设置 CLOUDFLARE_API_TOKEN 环境变量 |
| "401 未授权" | 检查令牌是否有效 |
| "403 禁止访问" | 令牌缺少所需权限 |
| "未找到区域" | 确认域名在您的账户中 |