Loading... ## 自建DDNS解决动态IP服务器访问问题 * 把域名接入cloudflare * 获取Global API Key * 设置用于 DDNS 解析的二级域名,流量不经过CDN(云朵变灰) * 下载 DDNS 脚本 * 修改 DDNS 脚本并补充相关信息 * 设置定时任务 ### 把域名接入cloudflare 打开[cloudflare](https://www.cloudflare.com/zh-cn/),登陆账号添加网站按照提示操作 ### 获取Global API Key 访问 [https://dash.cloudflare.com/profile](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 脚本并补充相关信息 ``` nano cf-v4-ddns.sh ``` ``` # incorrect api-key results in E_UNAUTH error # 填写 Global API Key CFKEY= # Username, eg: user@example.com # 填写 CloudFlare 登陆邮箱 CFUSER= # Zone name, eg: example.com # 填写需要用来 DDNS 的一级域名 CFZONE_NAME= # Hostname to update, eg: homeserver.example.com # 填写 DDNS 的二级域名(只需填写前缀) CFRECORD_NAME= ``` 首次运行脚本,输出内容会显示当前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 ``` > 2 分钟检测一次,IP 是否改变。 ### 安装 crontab 可能提示没有安装 crontab,所以需要运行下面的内容 ``` apt-get install vixie-cron #报错就报错,没关系的,下一步 apt-get install crontabs ``` 等添加了任务之后,再手动运行 crontab ``` service crond start #运行 crontab service crond status #查看 crontab 状态 chkconfig crond on #Centos6 允许 crontab 自启动 systemctl enable crond.service #Centos7 允许 crontab 自启动 ``` <hr class="content-copyright" style="margin-top:50px" /><blockquote class="content-copyright" style="font-style:normal"><p class="content-copyright">版权属于:大漠孤狼</p><p class="content-copyright">本文链接:<a class="content-copyright" href="https://www.dmgls.com/1358.html">https://www.dmgls.com/1358.html</a></p><p class="content-copyright">转载时须注明出处及本声明</p></blockquote> Last modification:November 19th, 2022 at 03:39 am © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 Appreciate the author
2 comments
cloudflare的ddns是不是不能用根域名,我只要用根域名就提示这个WARN : Could not detect 'record id' for host.domain.tld: '@.123.xyz'
大佬为什么我这里显示您的网站连接不安全