Mikrotik RB750g DDNS Script for no-ip and DynDNS

Hi,

I have looked around but cant find a script to work on my unit.
the scripts i do find is for old os 3.x further more I need to automate the update once ip changes ..every like 24 hours

regards

running OS 5.6

This works for me. It is not for DynDNS but you can use it for ChangeIP.com.

# Written by Sam Norris, ChangeIP.com
# Copyright ChangeIP.com 2009
# For support send mail to Support@ChangeIP.com
#
# 2009-06-22 RouterOS 3.25 Tested
# 2009-10-05 RouterOS 4.01rc1 Tested
#
# OVERVIEW:         %
#  This script will update a ChangeIP.com dynamic dns hostname
#  with an ip address located directly on an interface.
#                   %
# NOTES:            %
#  IF THIS SCRIPT DOES NOT PRODUCE ANY OUTPUT PLEASE COPY AND PASTE IT
#  AGAIN.  THERE PROBABLY IS A LINE BREAK IN THE WRONG PLACE! Once you
#  have created this script and tested that it works by running it
#  manually you can schedule it to run every few minutes.
#                   %
# CONFIGURATION FIELD DEFINITIONS:
#  ddnsuser:  Enter your ChangeIP.com user id.
#  ddnspass:  Enter your ChangeIP.com password.
#  ddnshost:  Enter the hostname (www.example.com) to update.
#  ddnsinterface:  Enter an interface name to watch - case sensative.
#                   %
#                   %
#                   %
#                   %
#               %   %   %
#                %  %  %
#                 % % %
#                   %
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EDIT YOUR DETAILS / CONFIGURATION HERE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:global ddnsuser "puthereusername"
:global ddnspass "putherepass"
:global ddnshost "hostname.domain.com"
:global ddnsinterface "The name of the interfece to monitor eg.. T-ComWAN"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END OF USER DEFINED CONFIGURATION
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:global ddnssystem ("mt-" . [/system package get [/system package find name=system] version] )
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
:global ddnslastip

:if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }

:if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }

:if ([ :typeof $ddnsip ] = "nothing" ) do={

:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")

} else={

  :if ($ddnsip != $ddnslastip) do={

    :log info "DDNS: Sending UPDATE!"
 :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
    :global ddnslastip $ddnsip

  } else={ 

    :log info "DDNS: No changes necessary."

  }

}

I dont think you should change anything but this:

:global ddnsuser "puthereusername"
:global ddnspass "putherepass"
:global ddnshost "hostname.domain.com"

I have this working fine on RouterOS 5.2 and ChangeIP.com account

And don’t forget to call the script every minute (for example) - (use WinBox) on

/system scheduler

I use DNSoMatic which updates DynDNS, OpenDNS, and many more.

DNS-oMatic Updater Script

# DNSoMatic automatic DNS updates
# User account info of DNSoMatic
:global maticuser "user"
:global maticpass "password"
:global matichost "Yourhost"
# No more changes need

:global previousIP

# Print values for debug
:log info "DNSoMatic: Updating dynamic IP on DNS for host $matichost"
:log info "DNSoMatic: User $maticuser y Pass $maticpass"
:log info "DNSoMatic: Last IP $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"
: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]
:global currentIP [:pick $result $startLoc $endLoc]
:log info "DNSoMatic: IP actual $currentIP"

# Touching the string passed to fetch command on "src-path" option
:local str "/nic/update?hostname=$matichost&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"

# Comment out next line to force update #
:if ($currentIP != $previousIP) do={
:log info "DNSoMatic: Update need"
:set previousIP $currentIP
:log info "DNSoMatic: Sending update $currentIP"
:log info [ :put [/tool fetch host=MT user=$maticuser password=$maticpass mode=http address="updates.dnsomatic.com" src-path=$str dst-path=$matichost]]
:log info "DNSoMatic: Host $matichost updated on DNSoMatic with IP $currentIP"
}  else={
:log info "DNSoMatic: Previous IP $previousIP and current $currentIP equal, no update need"
}

If you just want to use DynDNS I believe this works.

/system script
add name=DynDNS policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="# Set needed variables\r\
    \n:local username \"USERNAME\"\r\
    \n:local password \"PASSWORD\"\r\
    \n:local hostname \"HOSTNAME\"\r\
    \n:global systemname [/system identity get name]\r\
    \n\r\
    \n:if (\$systemname  = \"Site1\" ) do= {\r\
    \n:set hostname \"yourdomain1.dyndns.org\"\r\
    \n}\r\
    \n:if (\$systemname  = \"Site2\" ) do= {\r\
    \n:set hostname \"yourdomain2.dyndns.org\"\r\
    \n}\r\
    \n:if (\$systemname  = \"Site3\" ) do= {\r\
    \n:set hostname \"yourdomain3.dyndns.org\"\r\
    \n}\r\
    \n\r\
    \n:global dyndnsForce\r\
    \n:global previousIP\r\
    \n\r\
    \n# print some debug info\r\
    \n:log info (\"UpdateDynDNS: username = \$username\")\r\
    \n:log info (\"UpdateDynDNS: password = \$password\")\r\
    \n:log info (\"UpdateDynDNS: hostname = \$hostname\")\r\
    \n:log info (\"UpdateDynDNS: previousIP = \$previousIP\")\r\
    \n\r\
    \n# get the current IP address from the internet (in case of double-nat)\r\
    \n/tool fetch mode=http address=\"checkip.dyndns.org\" src-path=\"/\" dst-path=\"/dyndns.checkip.html\"\r\
    \n:local result [/file get dyndns.checkip.html contents]\r\
    \n\r\
    \n# parse the current IP result\r\
    \n:local resultLen [:len \$result]\r\
    \n:local startLoc [:find \$result \": \" -1]\r\
    \n:set startLoc (\$startLoc + 2)\r\
    \n:local endLoc [:find \$result \"</body>\" -1]\r\
    \n:local currentIP [:pick \$result \$startLoc \$endLoc]\r\
    \n:log info \"UpdateDynDNS: currentIP = \$currentIP\"\r\
    \n\r\
    \n# Remove the # on next line to force an update every single time - useful for debugging,\r\
    \n#  but you could end up getting blacklisted by DynDNS!\r\
    \n\r\
    \n#:set dyndnsForce true\r\
    \n\r\
    \n# Determine if dyndns update is needed\r\
    \n# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html\r\
    \n:if ((\$currentIP != \$previousIP) || (\$dyndnsForce = true)) do={\r\
    \n    :set dyndnsForce false\r\
    \n    :set previousIP \$currentIP\r\
    \n    /tool fetch user=\$username password=\$password mode=http address=\"members.dyndns.org\" \\\r\
    \n       src-path=\"/nic/update\?hostname=\$hostname&myip=\$currentIP\" dst-path=\"/dyndns.txt\"\r\
    \n    :local result [/file get dyndns.txt contents]\r\
    \n    :log info (\"UpdateDynDNS: Dyndns update needed\")\r\
    \n    :log info (\"UpdateDynDNS: Dyndns Update Result: \".\$result)\r\
    \n    :put (\"Dyndns Update Result: \".\$result)\r\
    \n} else={\r\
    \n    :log info (\"UpdateDynDNS: No dyndns update needed\")\r\
    \n}\r\
    \n"

Use either of those then schedule the script as ivugrinec said.