Cloudflare搭建DDNS教程

Cloudflare搭建DDNS教程

把域名接入cloudflare

打开cloudflare,登陆账号添加网站按照提示操作

访问 https://dash.cloudflare.com/profile在页面下方找到 Global API Key,点击右侧的 View 查看 Key,并保存下来

设置用于 DDNS 解析的二级域名,流量不经过CDN(云朵变灰)

添加一条A记录,例如:hkt.test.com,Proxy status设置成DNS only

下载DDNS一键脚本

1
curl https://raw.githubusercontent.com/zhojielun/cloudflare-api-v4-ddns/master/cf-v4-ddns.sh > /root/cf-v4-ddns.sh && chmod +x /root/cf-v4-ddns.sh

修改DDNS脚本补充你自己的信息

1
vim cf-v4-ddns.sh

# incorrect api-key results in E_UNAUTH error

# 填写 Global API Key

1
CFKEY=

# Username, eg: [email protected]

# 填写 CloudFlare 登陆邮箱

1
CFUSER=

# Zone name, eg: example.com

# 填写需要用来 DDNS 的一级域名

1
CFZONE_NAME=example.com

# Hostname to update, eg: homeserver.example.com

# 填写 DDNS 的二级域名(只需填写前缀)

1
CFRECORD_NAME=homeserver.example.com

设置完毕运行脚本

1
./cf-v4-ddns.sh

首次运行脚本,输出内容会显示当前IP,进入cloudflare查看 确保IP已变更为当前IP

设置定时任务(环境centos7)

1
crontab -e
1
*/1 * * * * /root/cf-v4-ddns.sh >/dev/null 2>&1

也可以执行

1
2
3
4
<(curl -Ls https://git.io/cloudflare-ddns) -k cloudflare-api-key \
-h host.example.com \ # fqdn of the record you want to update
-z example.com \ # will show you all zones if forgot, but you need this
-t A|AAAA # specify ipv4/ipv6, default: ipv4