I’m new to Mikrotik. I just bought the HAP AC2 and i’m on the configuration period. I have set this router as the main router of my home network which also connects to the internet via PPPoE through the ISP modem. I have also set up Pi-Hole as the local DNS. While i was trying to find a script for updating my DynDNS domain i found in the official wiki a page with a script for this purpose. https://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_No-IP_DNS. I tried the script several times with no success but after some debugging i noticed that firstly, the router couldn’t resolve the domain (http://dynupdate.no-ip.com/) so i found out that the user must have set a DNS IP address under IP->DNS->Servers (maybe this must only be set up in the case you are using a local DNS as i do) and the second one was that the $previousIP variable in the script it seemed that on each run didn’t have the previous value. So i noticed here that the suggested permissions write, test, read wasn’t enough for the global variable to be set. So i granted policy permissions also and now everything works.
If the $previousIP is not set then on each run the script will send an ip update request to the DynDNS server even when the ip has not be changed (this is only noticeable though the logs. Otherwise the user is not affected)
So these two are suggestions if you are interested to be added in your official wiki page.
You can use MikroTik Colud DNS, its free. Then you can point your dyndns to the MikroTiok clod DNS name. (if its possible)
Or drop dyndns and only use Mikrotik Cloud DNS as your public DNS name.
IP->Cloud DDNS Enable.
Then you should get a fixed DNS name like this:
PublicIP: 65.232.13.123 (your outside IP)
DNS Name: 6f3806exxxxx.sn.mynetname.net (Serial number your router + .sn.mynetname.net)
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org"
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no"
dst-path="/dyndns.txt"
:delay 1
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
then run this in command
/system scheduler
add interval=1m name=DynDns on-event=DynDns policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup
Thanks for the script.
Use code tags. Select text and click the </> button.
Like this: (with tabs as well)
# Set needed variables
:local username "YOURUSERNAME"
:local password "YOURPASSWORD"
:local hostname "YOURHOSTNAME.dyndns.org"
:global dyndnsForce
:global previousIP
# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]
# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"
# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true
# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
dst-path="/dyndns.txt"
:delay 1
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
hi I am new here, I got software routeros 4.86.1 and in my IP section, I did not see “IP cloud” feature in the list , I like to use my dynamic service with dyndns, can anyone can help me to get this feature back to IP section ?
# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")
Just came across this and the script is really helpful!
Would like to share a modified version that uses the new API (using Client Update Key) and gives a warning if forced update is turned on in case anyone is interested.
Tested with RouterOS 7.2.3
# Set needed variables
:local username "DYN_USER_NAME"
:local clientkey "DYN_CLIENT_KEY"
:local hostname "HOST_TO_UPDATE"
:global dyndnsForce
:global previousIP
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]
# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"
# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true
# Determine if dyndns update is needed
# more dyndns updater request details https://help.dyn.com/remote-access-api/perform-update/
:log info "UpdateDynDNS: previousIP = $previousIP"
:if ($dyndnsForce = true) do={ :log warning "UpdateDynDNS: Forced update on" }
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
/tool fetch mode=https \
url="https://$username:$clientkey@members.dyndns.org/v3/update?hostname=$hostname&myip=$currentIP" \
dst-path="/dyndns.txt"
:delay 1
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
I’m currently facing an issue with my MikroTik router after updating the firmware to version 7.12.1 a few days ago. I’m using the latest script with a DNS client key, and since the update, the DynDNS is not updating correctly.
The strange part is that the router indicates a successful update, showing the new IP, but when I check on the DynDNS website, the new IP is not assigned. I’ve already tried generating a new key, but unfortunately, that didn’t resolve the issue.
I’m reaching out to the community to see if anyone else is experiencing similar problems or has any insights into resolving this issue. Could it be a problem on the DynDNS side, or is there something specific to the MikroTik FW 7.12.1 update that might be causing this discrepancy?
I appreciate any assistance or advice you can provide.
Hey, sorry for my possibly bad English, I use a translator.
I did the update to 7.13 yesterday and also had problems with the script execution for dyndns.
I was able to solve the problem by activating “FTP” in the script.
I hope that this is perhaps also your problem and can be remedied.