注意要 僅限 DNS
獲取咱的Key https://dash.cloudflare.com/profile
先在控制面板找到咱的目前IP,然后到Cloudflare中新建一個A記錄,如:ddns.yourdomain.com,指向咱的當前IP
下載腳本
1 wget https://raw.githubusercontent.com/yulewang/cloudflare-api-v4-ddns/master/cf-v4-ddns.sh
這里需要填寫一個能返回咱的當前IP的網頁地址,下面提供一些
1 $ curl ifconfig.me 2 $ curl icanhazip.com 3 $ curl ident.me 4 $ curl ipecho.net/plain 5 $ curl whatismyip.akamai.com 6 $ curl tnx.nl/ip 7 $ curl myip.dnsomatic.com 8 $ curl ip.appspot.com 9 $ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\).*/\1/g'
修改腳本
# API key, see https://www.cloudflare.com/a/account/my-account,
# 上一步獲取的CFKEY
CFKEY=
#輸入你需要解析用來DDNS解析的根域名 eg: example.com
CFZONE=
# 暫時空着
CFID=
# 登陸CF的Username, eg: user@example.com
CFUSER=
# 填寫用來DDNS解析的二級域名,與上面設置的要一致, eg: ddns.yourdomain.com
CFHOST=
# Cloudflare TTL for record, between 120 and 86400 seconds
CFTTL=3600
# Get domain ID from Cloudflare using awk/sed and python json.tool
GETID=true
# Ignore local file, update ip anyway
FORCE=false
# 填寫上一步能正確返回咱的當前IP的網址, other examples are: bot.whatismyipaddress.com, https://api.ipify.org/ ...
WANIPSITE="myip.dnsomatic.com"
運行腳本
1 chmod +x cf-ddns.sh 2 ./cf-ddns.sh
第一次運行后,會顯示咱用於DDNS解析的二級域名的CFID,記錄下來
將CFID填入到配置文件中的CFID處
再次運行
1 ./cf-ddns.sh
設置自動運行
1 crontab -e 2 #不知道這樣寫對不對xD 3 0 * * * * /root/cf-ddns.sh >/dev/null 2>&1