Script to update current existing cloudflare record with current public address, meant to be used as an cloud alternative for cloudflare’s ddns.
I’m posting it here because when I needed everything I found on google was links to another post that didn’t even have anything useful at all…
Tested and working with the RouterOS v6.44 on a hAP Lite. (tested on this post’s date!)
If you need to get your zone ID you can just curl a zone list and manually get the ID from the returned json as I did!
Not going into the merit of puting it as an script option, if you need help doing this just contact me and I will help, but it’s very simple to do and I don’t think anyone will really need a hand…
:global cfu do={
:local cfi “THE_ZONE_ID”;
:local cfr “THE_RECORD_ID”;
:local cfe “ACCOUNT_EMAIL_ADDRESS”;
:local cfk “API_GLOBAL_KEY”;
:local cfd “THE_RECORD_DOMAIN”;
:local cfa [/ip cloud get public-address];
:local cfp true;
/tool fetch mode=https
http-method=put
url=“https://api.cloudflare.com/client/v4/zones/$cfi/dns_records/$cfr”
http-header-field=“content-type:application/json,X-Auth-Email:$cfe,X-Auth-Key:$cfk”
http-data=“{"type":"A","name":"$cfd","content":"$cfa","proxied":$cfp}”
output=none
}
=== UPDATE (03/04/2019) ===
If you need help setting it up, just follow this tutorial.
This is the first post on Google when searching for Mikrotik’s Cloudflare DDNS solutions, and I got my script’s original version here from OP. So adding my version here:
# Script name (must be same as you called the script)
:local scriptname "<YOUR_SCRIPT_NAME>"
:if ([:len [/system script job find script=$scriptname]]>1) do={
log info "Another copy of $scriptname is running.";
:error "Another copy of $scriptname is running.";
}
log info "Started $scriptname";
:local cfi "<YOUR_ZONE_ID>";
:local cfr "<YOUR_DNS_ENTRY_ID>";
:local ctk "<YOUR_API_TOKEN>";
:local cfd "<YOUR_TARGET_DOMAIN>";
:local cfa [/ip cloud get public-address];
:local cfp false;
/tool fetch mode=https\
http-method=put\
url="https://api.cloudflare.com/client/v4/zones/$cfi/dns_records/$cfr"\
http-header-field="content-type:application/json,Authorization:Bearer $ctk"\
http-data="{\"type\":\"A\",\"name\":\"$cfd\",\"content\":\"$cfa\",\"proxied\":$cfp}"\
output=file\
dst-path="$scriptname.txt"
Thanks for this… I was able to confirm this work’s great! I just added a quick check to see if the cfa variable matches the current public DNS setting, using this:
:resolve <domain name> server=1.1.1.1
Also added additional logging. And then wrapped it in an if/else statement. Scheduled it for every 30 minutes. Working really well!