Hublog随手记录一些东西

Cloudflare 修改记录

使用脚本修改 cloudflare 上域名的记录值

获取区域 ID 和账户 ID

在 cloudflare 域名 -> 概述 的右下角可以获取到域名的区域 ID 和 账户 ID,也可以用以下代码获取(需要区域 ID 和 API 令牌)

1
2
3
curl -X GET "https://api.cloudflare.com/client/v4/zones/zone_identifier" \
    -H "Content-Type:application/json" \
    -H "Authorization: Bearer 123"
创建 API 令牌
API 令牌我的个人资料 -> API 令牌 -> 创建令牌

获取记录 ID

  1. 使用 API 密钥

使用时替换下面 zone_identifier、record、name、邮箱和 API 密钥

1
2
3
4
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/zone_identifier/dns_records?type=A&name=example.org" \
    -H "X-Auth-Email: xxx@xxx.com" \
	-H "X-Auth-Key: 123" \
	-H "Content-Type: application/json"
  1. 使用 API 令牌

使用时替换下面 zone_identifier、record、name 和 API 令牌

1
2
3
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/zone_identifier/dns_records?recod=A&name=example.org" \
    -H "Authorization: Bearer 123" \
	-H "Content-Type: application/json"

修改记录

使用 API 令牌修改记录

使用时替换下面 zone_identifier、identifier、type、content、name 和 API 令牌

identifier 就是上面命令获取到的 id,ttl 单位为秒,填 0 时为自动

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
curl --request PUT \
  --url https://api.cloudflare.com/client/v4/zones/zone_identifier/dns_records/identifier \
    -H "Authorization: Bearer 123" \
    -H "Content-Type: application/json" \
  --data '{
  "type": "A",
  "comment": "Domain verification record",
  "content": "192.168.0.10",
  "name": "example.org",
  "proxied": false,
  "ttl": 0
}'

官方文档:Cloudflare API Documentation

0%