• 首页
  • 数据库
    • mysql
  • web服务器
    • nginx
    • Apache
  • 操作系统
    • Centos
    • Debian
    • Ubuntu
    • mac
    • windows
  • 编程语言
    • html
    • php
  • 集群
    • mycat
  • 其它
欢迎光顾我的个人博客
  1. 首页
  2. 文章
  3. 其它
  4. 正文

利用CloudFlare API搭建DDNS

2020年06月07日 978点热度 0人点赞 0条评论

首先你要有Cloudflare账号,并且有可用域名托管在CF,添加一个A记录(你想用来做DDNS的域名即可)

搭建前需要有 Python 环境,安装依赖

pip install pyyaml
pip install requests

接下来开始获取源码

git clone https://github.com/ethaligan/cloudflare-ddns.git

开始配置

cd cloudflare-ddns/zones
cp example.com.yml xxx.xxx.yml

注意将上面的xxx.xxx替换为你的根域名,然后编辑它,参考如下

%YAML 1.1
# Cloudflare DDNS example configuration
---

# Your Cloudflare email address
cf_email: '你的CF注册账号'

# Your Cloudflare API key
# https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key
cf_api_key: 你的Global API Key

# Cloudflare zone name
# If you're updating 'ddns.example.com' set this to 'example.com'
cf_zone: 你的根域名

# List of records
# If you're updating 'example.com' record, set its name to '@'.
# Only write the subdomain ('ddns' for 'ddns.example.com')
cf_records:
    - '@':
        type: A
        proxied: true
        log: ERROR
    - '你的DDNS域名':
        type: A
    - '你的DDNS域名':
        type: AAAA
        ttl: 300
        proxied: false
        log: INFO

# This is the method used to discover the server's IP address
# The faster one is 'dig' but it may not be available on your system
# Available methods: 'http' or 'dig'
cf_resolving_method: 'http'

测试一下

cd ../
python cloudflare-ddns.py -z xxx.xxx

一般是没问题的,用在没有V6的机器上会提示找不到AAAA记录(这不是废话吗。。。)直接注释掉就好了

加个定时任务crontab -e

添加如下两行,即每隔半个小时自动重新获取当前IP并更新一次

# Every 30 minutes, update my Cloudflare records.
*/30 * * * * python /root/cloudflare-ddns/cloudflare-ddns.py -z xxx.xxx
标签: CloudFlare DNS
最后更新:2020年07月16日

多洛夫

多看多想多研究,总会有创新

点赞
< 上一篇
下一篇 >

文章评论

取消回复

多洛夫

多看多想多研究,总会有创新

博客更新日期
2025 年 6 月
一 二 三 四 五 六 日
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« 7 月    
分类
标签聚合
Termux Shell DNS ffmpeg 谷歌浏览器插件 mac mysql 视频截图 centos wordpress 域名邮箱 lls haproxy Google Launchctl Photoshop Yandex 图片格式转换 php google插件

© 2020 多洛夫