An alternate to changeip.com (free ddns) .
From few days , we were having issues in updating our mikrotik/linux base machines dynamic ip to free DDNS service like changeip.com, therefore today I tested DYNU as an alternate and it worked very good. we can use it as backup or primary ddns service for our mikrotik routers.
First create account at http://www.dynu.com, add your required host. and then add script and schedule it to run after every 5 (or xx) minutes
Mikrotik Script for Dynu ddns.
The below script is working 100% on Mikrotik 5.x and 6.x versions.
[Tested as of now / 1st-DEC-2015]
(You can copy paste following code in mikrotik by going to SYSTEMS / SCRIPTS / CLICK ON + sign to add script, and paste following.
NOTE: MAKE SURE YOU CHANGE THE REQUIRED FIELDS BEFORE DEPLOYMENT.
SCRIPT NAME: “DYNU“
1- SCRIPT FOR DSL MODEM IN BRIDGE MODE, MIKROTIK HAVE THE PUBLIC IP ADDRESS AT WAN INTERFACE.
(FOR BRIDGE MODE, PUBLIC IP IS DIRECTLY ON MIKROTIK WAN INTERFACE)
NOTE: If you have multiple IP address configured on WAN interface, it will give you error of “Invalid internal item number”
############################################## # DYNU SCRIPT for Mikrotik , DSL Modem BRIDGE MODE, # Wan dialing is done by mikrotik so public ip is on mikrotik directly # CHANGE THE FOLLOWING ACCORDING TO YOUR CREDENTIALS # Syed Jahanzaib / aacable at hotmail dot com # #################################################### :global ddnsuser DYNU_USER :global ddnspass "DYNU_PASSWORD" :global theinterface "WAN_INTERFACE_NAME" :global ddnshost "YOUR_DYNU_HOSTNAME.dynu.com" #### Donot change below this line #### :global ipddns [:resolve $ddnshost]; :global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ] :if ([ :typeof $ipfresh ] = nil ) do={ :log info ("DynuDDNS: No IP address on $theinterface .") } else={ :for i from=( [:len $ipfresh] - 1) to=0 do={ :if ( [:pick $ipfresh $i] = "/") do={ :set ipfresh [:pick $ipfresh 0 $i]; } } :if ($ipddns != $ipfresh) do={ :log info ("DynuDDNS: IP-Dynu = $ipddns") :log info ("DynuDDNS: IP-Fresh = $ipfresh") :log info "DynuDDNS: Update IP needed, Sending UPDATE...!" :global str "/nic/update?hostname=$ddnshost&myip=$ipfresh" /tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/Dynu.".$ddnshost) :delay 1 :global str [/file find name="Dynu.$ddnshost"]; /file remove $str :global ipddns $ipfresh :log info "DynuDDNS: IP updated to $ipfresh!" } else={ :log info "DynuDDNS: dont need changes"; } }
Now run it and watch the results.
2- SECOND SCRIPT FOR DSL MODE, MIKROTIK IS CONNECTED TO INTERNET BEHIND DSL. (NAT)
######################################## # DYNU DNS Script for Mikrotik Behind DSL # 14th JAN-2015 # Syed Jahanzaib / aacable at hotmail dot com # #################################################### # 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" :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 "" -1] :local currentIP [:pick $result $startLoc $endLoc] #:log warning "UpdateDynDNS: currentIP = $currentIP" ###################################################### :global ddnsuser DNSUSERNAME :global ddnspass "DNSPASSWORD" :global ddnshost "YOURHOST.dynu.com" :global ipddns [:resolve $ddnshost]; #:global ipddns 1.2.3.4 :if ($ipddns != $currentIP) do={ :log info ("DynuDDNS: IP-Dynu = $ipddns") :log info ("DynuDDNS: IP-Fresh = $currentIP") :log info "DynuDDNS: Update IP needed, Sending UPDATE...!" :global str "/nic/update?hostname=$ddnshost&myip=$currentIP" /tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/Dynu.".$ddnshost) :delay 1 :global str [/file find name="Dynu.$ddnshost"]; /file remove $str :global ipddns $currentIP :log info "DynuDDNS: IP updated to $currentIP!" } else={ :log info "DynuDDNS: dont need changes"; } }
To scheudle it to run every 5 minutes , use
/system scheduler add disabled=no interval=5m name=dynu on-event=dynu policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=jan/01/1970 \ start-time=00:00:00
Regard’s
Syed Jahanzaib
It works as per in the script, thankkkk youuuu ! I have question off this topic. Do mikrotik have “Ip sla” ?
I need script for BGP failover to happen as how we can do in Cisco. anyone can help or any solution already available ? paste the link here, I can have a look at it. THANK YOU AGAIN!
LikeLike
Comment by Saran — December 2, 2015 @ 8:51 PM
Aoa! script updating my local IP (192.168.x.x) to DYNU DDNS. please help….thanx in adv
LikeLike
Comment by Asif Siddiqui — December 30, 2015 @ 10:31 PM
need some help anyone here?
LikeLike
Comment by Asif Siddiqui — January 2, 2016 @ 12:20 AM
Aoa! script updating my local IP (192.168.x.x) to DYNU DDNS. please help
LikeLike
Comment by Asif Siddiqui — January 12, 2016 @ 5:35 PM
I have updated the post. 2 scripts are now posted. one for Mikrotik with direct public ip (like modem is in bridge mode and mikrotik dialing the net via pppoe-out1)
second script is for mikrotik which is behind dsl NAT. use that one for your mikrotik and do let me know the results.
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — January 14, 2016 @ 12:07 PM
does not work on version 6
thanks
LikeLike
Comment by Mohsen Ahmed — January 16, 2016 @ 4:20 AM
funciona perfeito x86 mikroitk 6.37.3
LikeLike
Comment by Rafael dos Santos Pereira — December 17, 2016 @ 6:39 PM
English?
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — December 19, 2016 @ 12:53 PM
scheduler not working on yours command
this command working fine thankx
/system scheduler add name=dynu interval=00:05 on-event=”/system script run dynu\r\n”
LikeLike
Comment by fasih ur rehman — December 15, 2016 @ 12:05 AM
Dear,
I’tried your second script for a device behind NAT, but it didn’t work. The OS version is 6.35, the device is hAP.
Do I need to do some port forwarding on the router (ADSL modem), if yes, what port do I need to open?
Best regards, Paolo
LikeLike
Comment by Paolo Zovic — February 19, 2017 @ 6:56 PM
work good
LikeLike
Comment by Mo Abdali — March 5, 2017 @ 6:44 PM