Mikrotik Setup Dynamically Changing IP With No-IP Api
Preamble
Directions for how to configure dynamic DNS on a mikrotik. It leverages the No-IP REST API and the mikrotik's built-in scripting environment.
Dynamically Updating the IP
Code
Use the System>Scripts page and create a new script with this code. Change the variables under the Script Settings block. Set the name of the script to "NoIP"
##############Script Settings##################
:local NOIPUser "USERNAME"
:local NOIPPass "PASSWORD"
:local WANInter "ether1"
:local NOIPDomain "NO-IP.DDNS.NET"
###############################################
# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$WANInter" disabled=no] address]
# Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
}
}
:if ([:resolve $NOIPDomain] != $currentIP) do={
/tool fetch mode=http user=$NOIPUser password=$NOIPPass url="http://dynupdate.no-ip.com/nic/update\3Fhostname=$NOIPDomain&myip=$currentIP" keep-result=no
:log info "NO-IP Update: $NOIPDomain - $currentIP"
}
Running and scheduling the script
Run the script a single time to update your DNS.
# "NoIP" is the name I set for the script
/system/script/run NoIP
Schedule the script to run every few minutes.
# The name I gave my script was "NoIP"
/system/scheduler/ add name=NoIPCheck interval=3m on-event=NoIP