we use the dyndns service from http://www.no-ip.com on our behind nat Mikrotik Router distributed around Connectivia sites.
For this reason we delivered (tested on RouterOs 5.x) a new one script as a merge of the two faboulous scripts already available on wiki.mikrotik.com to have a dyndns update script
specific for No-IP dyndns service when Mkt devices are behind nat. Thanks to the creator of changeip script published on Wiki page http://wiki.mikrotik.com/wiki/Scripts- We hope it’s no problem to use the base or some parts .
Here you have the script :
#Dynamic DNS Update Script for No-IP DNS behind nat
# Set needed variables
:local username "uzername"
:local password "pazzword"
:local host "dreammachine.no-ip.org"
:global previousIP
# print some debug info
:log info ("Update No-IP DNS: username = $username")
:log info ("Update No-IP DNS: hostname = $host")
:log info ("Update No-IP DNS: previousIP = $previousIP")
#
# behind nat - get the publòic address using dyndns url http://checkip.dyndns.org
/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]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "No-IP DNS: currentIP = $currentIP"
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
:set previousIP $currentIP
:local url "http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP&hostname=$host"
:log info "No-IP DNS: Sending update for $host"
/tool fetch url=$url user=$username password=$password mode=http dst-path=("no-ip_ddns_update.txt")
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
}
else={
:log info "No-IP: update not needed "
}
# end
Hi! I tested this script to work on RB450G with 5.17. However, just wanted to clarify whether we need to specify the gateway interface for this to be more effective. Because in my previous script, the gateway interface was specified. Thanks.
Thank you for the script and a suggestion for enhancement. Because my IP address don’t change often, I still get the monthly e-mail remind me to log into my no-ip.com account. Can the script be changed so it will update with a dummy IP first then the real one every X days?
Thank you again.
I’ve created a newer Updater which includes the following features:
[]using IP Cloud to get the public IP (requires ROS v6.14)
[]updating the host via https
[]automatically updates every 3 minutes
[]does not create any files
Just copy the following Code into a textfile
edit the USER,PASS and HOST
and paste it into the CLI and it will create the Updater:
ROS Version >= 6.27
Add a script with read,write,test policy called no-ip_update:
#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "USER"
:local password "PASS"
:local host "HOST"
:global previousIP
# behind NAT - using MikroTik IP Cloud feature
#current IP
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
:log info "No-IP DNS: currentIP = $currentIP"
#compare IPs
:if ($currentIP not $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
#current IP overrides previous
:set previousIP $currentIP
:local url "https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
:log info "No-IP DNS: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end
Add a script with read,write,test policy called no-ip_update:
#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "USER"
:local password "PASS"
:local host "HOST"
:global previousIP
# behind NAT - using MikroTik IP Cloud feature
#current IP
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
:log info "No-IP DNS: currentIP = $currentIP"
#compare IPs
:if ($currentIP not $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
#current IP overrides previous
:set previousIP $currentIP
:local url "https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
:log info "No-IP DNS: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end
#current IP
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
:log info “No-IP DNS: currentIP = $currentIP” #compare IPs
:if ($currentIP not $previousIP) do={
:log info “No-IP: Current IP $currentIP is not equal to previous IP, update needed” #current IP overrides previous
:set previousIP $currentIP
:local url "> https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host> "
:log info “No-IP DNS: Sending update for $host” #sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info “No-IP DNS: Host $host updated on No-IP with IP $currentIP”
} else={
:log info "No-IP: update not needed "
}
end
I have tried this no ip updater behind nat and I am using RouterOS 6.29
But it seems it is not working. It just displays that my dynamic public IP changed but can’t update it to noip.
:log info “No-IP: Previous IP = $previousIP”
:log info “No-IP: Current IP = $currentIP”
#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info “No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed” #current IP overrides previous
:local url “https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host”
:log info “No-IP: Sending update for $host” #sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info “No-IP: Host $host updated on No-IP with IP $currentIP”
} else={
:log info "No-IP: update not needed "
}
#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "al1nm3ar"
:local password "!-IcedGuardian86-!"
:local host "pylonlabs.ddns.net"
# Get Previous IP
:local previousIP [/put [:resolve $host]]
# Get Current IP using MikroTik IP Cloud feature
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
# Logging IPs
:log info "No-IP: Previous IP = $previousIP"
:log info "No-IP: Current IP = $currentIP"
#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed"
#current IP overrides previous
:local url "https://dynupdate.no-ip.com/nic/update/?hostname=$host"
:log info "No-IP: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url http-method=post user=$username password=$password mode=https keep-result=no http-data="{\"myip\"=\"$currentIP\"}"
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end
# No-IP automatic Dynamic DNS update
#--------------- Change Values in this section to match your setup ------------------
# No-IP User account info
:local noipuser "xxxxxxxxxx"
:local noippass "xxxxxxxxxx"
# Set the hostname or label of network to be updated.
# Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.
# To specify multiple hosts, separate them with commas.
:local noiphost "xxxxxxxxx.noip.com"
# Change to the name of interface that gets the dynamic IP address, in my case: pppoe-out1
:local inetinterface "pppoe-out1"
#------------------------------------------------------------------------------------
# No more changes need
:global previousIP
:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$inetinterface" 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 ($currentIP != $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
:set previousIP $currentIP
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
:local url "http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
:local noiphostarray
:set noiphostarray [:toarray $noiphost]
:foreach host in=$noiphostarray do={
:log info "No-IP: Sending update for $host"
/tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=("no-ip_ddns_update-" . $host . ".txt")
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
}
} else={
:log info "No-IP: Previous IP $previousIP is equal to current IP, no update needed"
}
} else={
:log info "No-IP: $inetinterface is not currently running, so therefore will not update."
}
I was originally posting because I cant get it working , but got it working in the end, so heres my solution for those new to Mikrotik:
I first created a Script for the NoIp which worked when I manually run it, but it did not run when I put it in the scheduler:
Heres is what worked:
Caps in the names don’t work.
Script Name: noip
Policy: I left it at default all ticked.
Source:
#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "NoIP Username here (Not your email address, your Username"
:local password "NoIP Password Here"
:local host "NoIP Hostname here"
# Get Previous IP
:local previousIP [/put [:resolve $host]]
# Get Current IP using MikroTik IP Cloud feature
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
# Logging IPs
:log info "No-IP: Previous IP = $previousIP"
:log info "No-IP: Current IP = $currentIP"
#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed"
#current IP overrides previous
:local url "https://dynupdate.no-ip.com/nic/update/?hostname=$host"
:log info "No-IP: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url http-method=post user=$username password=$password mode=https keep-result=no http-data="{\"myip\"=\"$currentIP\"}"
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end
Scheduler Settings:
Name: noip
Interval: I initially put it at 0:00:05 for testing to see if it runs, changed it to 00:05:00 after it worked.
Policy: All Defualt Ticked
On Event:
/system script run noip