Difference between revisions of "Dynamic DNS Update Script for DNSoMatic.com behind NAT"

From MikroTik Wiki
Jump to: navigation, search
(Created page with 'This script is a solution made of others solutions (nothing new). The goal is to update your account on DNSoMatic.com. The main advantage on this solution is that DNSoMatic offer…')
 
Line 2: Line 2:
 
The goal is to update your account on DNSoMatic.com. The main advantage on this solution is that DNSoMatic offers the possibility of propagating DNS updates to thirth party DNSlike systems like OpenDNS, DynDNS, Change IP and other 27 more.
 
The goal is to update your account on DNSoMatic.com. The main advantage on this solution is that DNSoMatic offers the possibility of propagating DNS updates to thirth party DNSlike systems like OpenDNS, DynDNS, Change IP and other 27 more.
  
Thanks all for your solutions... with this solution DNS filtering from OpenDNS gets open.
+
Thanks all for your solutions... with this solution DNS filtering option from OpenDNS gets open without client software.
  
 +
Note: The script below is '''RouterOS 4.2 Tested'''!  It should also work on 3.x series RouterOS.
 +
 +
<pre>
 
# DNSoMatic automatic DNS updates
 
# DNSoMatic automatic DNS updates
 
# User account info of DNSoMatic
 
# User account info of DNSoMatic
Line 30: Line 33:
 
:log info "DNSoMatic: IP actual $currentIP"
 
:log info "DNSoMatic: IP actual $currentIP"
  
# Touching the string passed to fech command on "src-path" option
+
# 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"
 
:local str "/nic/update?hostname=$matichost&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
  
Line 42: Line 45:
 
:log info "DNSoMatic: Previous IP $previousIP and current $currentIP equal, no update need"
 
:log info "DNSoMatic: Previous IP $previousIP and current $currentIP equal, no update need"
 
}
 
}
 +
</pre>
 +
 +
This will also need you to configure scheduler entry for periodical runs.
  
 
gwicon 28/nov/2009
 
gwicon 28/nov/2009

Revision as of 21:46, 28 November 2009

This script is a solution made of others solutions (nothing new). The goal is to update your account on DNSoMatic.com. The main advantage on this solution is that DNSoMatic offers the possibility of propagating DNS updates to thirth party DNSlike systems like OpenDNS, DynDNS, Change IP and other 27 more.

Thanks all for your solutions... with this solution DNS filtering option from OpenDNS gets open without client software.

Note: The script below is RouterOS 4.2 Tested! It should also work on 3.x series RouterOS.

# 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"

: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"
}
This will also need you to configure scheduler entry for periodical runs.

gwicon 28/nov/2009