简单介绍
很久之前写的Cloudflare DDNS脚本了,之前是为了部署在本地IPV6的虚拟机上,利用Cloudflare反代出来。
一键脚本
#!/bin/sh
# +-------------------------------------------------------------------
# | Cloudflare DDNS脚本 支持自定义回源端口
# +-------------------------------------------------------------------
# | https://www.baota.me/post-454.html
# +-------------------------------------------------------------------
#区域ID
ZONE=''
#DNS记录ID
RECORD=''
#回源规则ID
RULE=''
#邮箱账号
EMAIL=''
# Global API Key 密钥
APIKEY=''
#完整域名
DOMAIN=''
ADDR=${1}
PORT=${2}
# 判断IPADDR变量是否为空
if [ -z "$ADDR" ]; then
#6.ipw.cn是获取ipv6的地址 如果你需要ipv6地址请使用4.ipw.cn
ADDR=$(curl -s "http://6.ipw.cn")
fi
# 域名解析 DNS 如果你想更新ipv4 请把下面的AAAA记录改成A记录
while true; do
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}" \
-H "X-Auth-Email: ${EMAIL}" \
-H "X-Auth-Key: ${APIKEY}" \
-H "Content-Type:application/json" \
--data "{\"type\":\"AAAA\",\"name\":\"${DOMAIN}\",\"content\":\"${ADDR}\",\"ttl\":60,\"proxied\":true}" > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
break
fi
done
# 判断PORT变量不为空则执行更新回源端口的命令
if [ ! -z "$PORT" ]; then
# 回源规则 Origin rule
while true; do
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/rulesets/${RULE}" \
-H "X-Auth-Email: ${EMAIL}" \
-H "X-Auth-Key: ${APIKEY}" \
-H "Content-Type:application/json" \
--data "{\"rules\":[{\"expression\":\"(http.host eq \\\"${DOMAIN}\\\")\",\"description\":\"natmap\",\"action\":\"route\",\"action_parameters\":{\"origin\":{\"port\":${PORT}}}}]}" > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
break
fi
done
fi
区域ID获取
选择一个域后,在右侧有个区域ID。
DNS记录ID获取
后续完善
回源规则ID获取
后续完善
Global API Key 获取
访问
https://dash.cloudflare.com/profile/api-tokens
在API 密钥栏内查看Global API Key
评论 (0)