Dynamic DNS Update – Mikrotik

Simple script for dynamic DNS update is presented below. Script was tested with changeip.org service and probably works for similar services too. This script works also behind NAT connection. To make it run automatically one must add this script to system scheduler.
NOTICE:

On every test script writes small file to a hard drive. One must remember that flash drive have limited amount of IO operations. Suggested interval between tests is one hour.

————–
# Dynamic DNS Update
# Written by Kacper Nowak
# Copyright bby.com.pl 2011
# Tested on RouterOS 4.13
#
# DESCRIPTION:
# This script will update a ChangeIP.com (probably will work with other services of this type)
# dynamic dns hostnamewith an ip address detected using checkip.dyndns.org page.
# WORKS WITH NAT.
#
# CONFIGURATION:
# ddnsuser: Enter your ChangeIP.com user id.
# ddnspass: Enter your ChangeIP.com password.
# ddnshost: Enter the hostname (example.changeip.com) to update.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EDIT CONFIGURATION HERE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:global ddnsuser „login”
:global ddnspass „password”
:global ddnshost „domain.changeip.org”
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END OF CONFIGURATION
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:global ddnssystem („mt-” . [/system package get [/system package find name=system] version] )
# 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]
:global ddnsip $currentIP
:global ddnslastip
:log info „CurrentIP: ddnsip = $ddnsip”
:log info „LastIP: lastIP = $ddnslastip”
:if ($currentIP != $ddnslastip) do={
:global ddnslastip $ddnsip
:log info „DDNS: Sending UPDATE!”
:log info [ :put [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ] ]
} else={
:log info „DDNS: No changes necessary.”
}

Leave a Comment

Question: