Cloudflare 搭建DDNS(脚本版)


自建DDNS解决动态IP服务器访问问题

  1. 把域名接入cloudflare
  2. 获取Global API Key
  3. 设置用于 DDNS 解析的二级域名,流量不经过CDN(云朵变灰)
  4. 下载 DDNS 脚本
  5. 修改 DDNS 脚本并补充相关信息
  6. 设置定时任务

把域名接入cloudflare

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

获取Global API Key

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

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

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

下载 DNNS 脚本

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

修改 DDNS 脚本并补充相关信息

vim cf-v4-ddns.sh

设置定时任务

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

./cf-v4-ddns.sh

设置定时任务

crontab -e

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

如果需要日志,替换上一行代码

*/2 * * * * /root/cf-v4-ddns.sh >> /var/log/cf-ddns.log 2>&1

声明:微博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Cloudflare 搭建DDNS(脚本版)


Carpe Diem and Do what I like