for Cloudflare as DDNS
using Cloudflare API v4
put ddns-start
at /jffs/scripts/
, setting values and set DDNS type to Custom at web Admin panel.
EMAIL
is your Cloudflare account
API
is your Cloudflare API Key. You can find at My Profile
-> API Tokens
-> Global API Key
-> View
TOKEN
is your Cloudflare API Token. You can create one at My Profile
-> API Tokens
-> Create Token
Only require API
OR TOKEN
. Use TOKEN
instead API
make more safe for your Cloudflare account.
ZONEID
can find by following command using Global Key
curl -X GET "https://api.cloudflare.com/client/v4/zones" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $API" \
-H "Content-Type: application/json"
or using API Tokens (require All zones permission for list)
curl -X GET "https://api.cloudflare.com/client/v4/zones" \
-H "X-Auth-Email: $EMAIL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
RECORDID
can find by following command using Global Key
curl -X GET "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?page=1&per_page=1000&order=type&direction=asc" \
-H "Content-Type:application/json" \
-H "X-Auth-Key: $API" \
-H "X-Auth-Email: $EMAIL"
or using API Tokens (your token setting may has problem if fail)
curl -X GET "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?page=1&per_page=1000&order=type&direction=asc" \
-H "Content-Type:application/json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-Auth-Email: $EMAIL"
RECORDNAME
is target domain name like ddns.dd-han.tw
RECORDTTL
is record TTL in second (1=auto, Must be between 120 and 2147483647)
if you don't want skip SSL check, run opkg install ca-certificates
and change command from curl -ks
to curl -s
Thanks, this is good help.
I noticed your instructions mention using the Global API key. I believe there might be a risk with with use of this key, especially if you're using Cloudflare for more then DDNS. If the router was compromised and they were clever enough to look through scripts/settings, then it would allow the an attacker to also hijack your Cloudflare account via the stored API key as it has global control of the account. This risk allows changing account info like e-mail or other settings unrelated to the key's intended use.
Not sure if it is a recent change,, but there are options now to add additional API keys for select services where you can grant permissions as needed (including DNS). This would be ideal to restrict misuse and ensure the script is only accessing the correct settings.