OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  cloudflare-api:连接 Cloudflare API 进行 DNS 管理与隧道配置

cloudflare-api:连接 Cloudflare API 进行 DNS 管理与隧道配置

 
  kernel ·  2026-02-08 06:58:49 · 3 次点击  · 0 条评论  

名称: cloudflare
描述: 连接 Cloudflare API 以管理 DNS、隧道和区域。当用户需要管理域名、DNS 记录或创建隧道时使用。
阅读时间:
- 用户询问 Cloudflare DNS 或域名
- 用户想要创建或管理 DNS 记录
- 用户需要设置 Cloudflare 隧道
- 用户想要列出其 Cloudflare 区域
元数据:
clawdbot:
emoji: "☁️"
requires:
bins: ["curl", "jq"]


Cloudflare 技能

连接 Cloudflare API,用于 DNS 管理、隧道和区域管理。

设置

1. 获取 API 令牌

  1. 访问 dash.cloudflare.com/profile/api-tokens
  2. 创建具有以下必要权限的令牌:
    • Zone:Read - 列出域名
    • DNS:Edit - 管理 DNS 记录
    • Account:Cloudflare Tunnel:Edit - 管理隧道
  3. 复制令牌

2. 配置

# 选项 A:存储在文件中(推荐)
echo "YOUR_API_TOKEN" > ~/.cloudflare_token
chmod 600 ~/.cloudflare_token

# 选项 B:环境变量
export CLOUDFLARE_API_TOKEN="YOUR_API_TOKEN"

3. 测试连接

./scripts/setup.sh

命令

区域(域名)

./scripts/zones/list.sh                    # 列出所有区域
./scripts/zones/list.sh --json             # JSON 格式输出
./scripts/zones/get.sh example.com         # 获取区域详情

DNS 记录

# 列出记录
./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 禁止访问" 令牌缺少所需权限
"未找到区域" 确认域名在您的账户中
3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor