Loading... # CloudFlare配置Dynamic DNS(DDNS)获取动态IP  在您的网络仅有动态公网IP,那么如何在外部访问是一个问题,本文向您介绍通过CloduFlare(简称CF)的DDNS来绑定域名解析。 具体如何把域名转入CF的DNS解析,可以自行搜索,或者打开CF官网根据介绍一步一步操作。 本站很久前分享过[he.net](https://dns.he.net/)的DDNS方法,如需了解可以详细看一下下面的这篇文章. <div class="preview"> <div class="post-inser post box-shadow-wrap-normal"> <a href="https://blog.yelvlab.cn/archives/282/" target="_blank" class="post_inser_a no-external-link no-underline-link"> <div class="inner-image bg" style="background-image: url(https://blog.yelvlab.cn/usr/themes/handsome/assets/img/sj/1.jpg);background-size: cover;"></div> <div class="inner-content" > <p class="inser-title">BPI-M1配置DDNS实现内网穿透</p> <div class="inster-summary text-muted"> 硬件:BPI-M1forum软件:Ubuntu14.04下载地址其他:动态公网IP,端口转发一、转入域名管理首先,... </div> </div> </a> <!-- .inner-content #####--> </div> <!-- .post-inser ####--> </div> ## CF上的准备工作 首先,需要在CF上添加一条解析记录,例如`test.yelvlab.cn`是要解析的域名,至于IP的话可以随意填写,后面会通过脚本自动更新。DDNS使用的域名不要开启CloudFlare的CDN,只用CF的DNS解析功能,也就是status一列对应域名的图标要是灰色的。 <span style='color:#A52A2A'>注意,解析类型:A记录是IPv4,AAAA是IPv6</span>  添加好域名解析后,去[CF Profile](https://dash.cloudflare.com/profile/api-tokens)里面拿到Global API Key(<span style='color:#A52A2A'>注意,千万不要外泄</span>)。  ## SHELL脚本 ### 获取脚本 下面这条命令是默认把脚本下载到你当前的操作目录,如果你要放在其他地方,可以修改命令或者进入到特定的目录。 ```shell curl https://raw.githubusercontent.com/lifehome/systemd-cfddns/master/src/cfupdater-v4 > ./cf-ddns-updater-v4.sh && chmod +x ./cf-ddns-updater-v4.sh ``` ### 修改个人信息 ```shell #!/bin/bash # Forked from benkulbertis/cloudflare-update-record.sh # CHANGE THESE # Global API Key (Deprecated + Dangerous) # Note: Please be caution as the Global API key can have unlimited access to **all** domain and features in your account. auth_email="john.appleseed@example.org" # The email used to login 'https://dash.cloudflare.com' auth_key="f1nd7h47fuck1n6k3y1ncl0udfl4r3c0n50l3" # Top right corner, "My profile" > "Global API Key" # API Token (Recommended) ##### ##### # WARNING: If you put any value inside the API Token variable, # # the script will automatically use the token and omit the Global API key, # # regardless if the Global API key is defined or not. # ##### ##### auth_token="xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Domain and DNS record for synchronization zone_identifier="f1nd7h3fuck1n6z0n31d3n71f13r4l50" # Can be found in the "Overview" tab of your domain record_name="dualstack.example.org" # Which record you want to be synced ``` 需要修改的部分只有开头的这部分,`auth_email`、`auth_key`、`auth_token`、`zone_identifier`和`record_name`。 `auth_email`: 输入你的CF登陆邮箱 `auth_key`: 输入你的Profile>Global API KEY `auth_token`: 这个要留空,具体可以看脚本内描述 `zone_identifier`: 这个在你的域名的概述页面的右下角可以找到 `record_name`: 这里填写要解析的域名 修改完保存退出,并在脚本的目录下执行: ```shell ./cf-ddns-updater-v4.sh ``` 执行结果如下则表示运行成功,并已经更新IP。  ## Crontab定时执行 脚本配置成功后,并且手动执行确认没问题了之后,就可以添加到`crontab`里面定时自动执行。`crontab -e`可以进入到编辑页面,并输入类似下面的命令,下面的命令表示每小时同步一次IP,还要注意修改你的脚本存放目录。 ```shell 0 * * * * /root/cf-ddns-updater-v4.sh > /dev/null 2>&1 ``` ## 参考 [利用CloudFlare设置Dynamic DNS(DDNS)获取动态IP](https://www.shiyanhe.com/149.html/) [benkulbertis/cloudflare-update-record.sh](https://gist.github.com/benkulbertis/fff10759c2391b6618dd/) **[systemd-cfddns](https://github.com/lifehome/systemd-cfddns)** Last modification:July 9, 2023 © Allow specification reprint Like 0 If you think my article is useful to you, please feel free to appreciate