使用CloudFlare搭建DDNS

 7个月前     2  

文章目录

CloudFlare DDNS

CloudFlare本身没有官方的DDNS支持,但可以使用CloudFlare API实做,我找了一个别人做好的CloudFlare-ddns,折腾一会儿就搭建好了。

首先从GitHub clone

copy
git clone https://github.com/thatjpk/cloudflare-ddns.git

进入目录

copy
cd cloudflare-ddns/

安装依赖

copy
pip install -r requirements.txt

重命名config.yaml.template文件

copy
mv config.yaml.template config.yaml

修改config.yaml

copy
nano config.yaml

差不多是这样的:

copy
%YAML 1.2
# CloudFlare DDNS updater script config.
---

# CloudFlare API key
# You can find this under Account > My account after logging into CloudFlare.
cf_key: 'cloudflare的API密钥'

# Email address for your CloudFlare account.
cf_email: '注册时使用的邮箱'

# Domain you're using CloudFlare to manage.
# If the host name you're updating is "ddns.domain.com", make this "domain.com".
cf_domain: '填入根域名'

# The subdomain you're using for your DDNS A record.
# If the host name you're updating is "ddns.domain.com", make this "ddns".
# However, if you're updating the A record for the naked domain (that is, just
# "domain.com" without a subdomain), then set cf_subdomain to an empty value.
cf_subdomain: '填入子域名'

# CloudFlare service mode. This enables/disables CF's traffic acceleration.
# Enabled (orange cloud) is 1. Disabled (grey cloud) is 0.
cf_service_mode: 0

# If set to true, prints a message only when the record changes or when
# there's an error.  If set to 'false', prints a message every time even if
# the record didn't change.
quiet: false

# If set to true then we call the ec2metadata service for the instance
# public ip address rather than an external service.
aws_use_ec2metadata: false

# If set to true dig will be used to fetch the public IP which is better
# but not available on all systems.
use_dig: false

创建子域名

运行脚本

copy
python cloudflare_ddns.py config_file_name.yaml

添加定时任务

copy
crontab -e

填入如下内容

copy
# Every 15 minutes, check the current public IP, and update the A record on CloudFlare.
*/15 * * * * /path/to/code/cloudflare_ddns.py /path/to/code/config.yaml >> /var/log/cloudflare_ddns.log

完成后每15分钟就会向cloudflare上传一次IP

暂无评论

暂无评论...