Difference between revisions of "Ros3 Dyn DNS"
 (New page: =Info= The following script should be created when you wish to update your ChangeIP.com Dynamic DNS account. Once created you should schedule this to run once in a while. The :global varia...)  | 
			
(No difference) 
 | 
Revision as of 13:32, 18 November 2008
Contents
Info
The following script should be created when you wish to update your ChangeIP.com Dynamic DNS account. Once created you should schedule this to run once in a while. The :global variables should be edited to include your unique username and password, interface name, etc. The script here should allow auto-detection of the default gateways interface name. This script below can be used if you have more than 1 WAN connection, but only 1 is active at a time.
This script will work as is, just navigate to System/Scripts and run it. This particular script works good with a 5 minute interval to update your Dynamic DNS with a scheduler.
Setup
For this script to function correctly, there are a few things that will need to be setup. Not necessary, but always good to have in place.
- Routerboard Identity Setup rb_Identity
 - Routerboard Time Setup, either manually rb_time_manual or via NTP rb_ntp_setup
 
Enhancements
- Check out Dynamic DNS Schedule to create a schedule, that will run the script at a predefined period.
 
Script
# Define User Variables
- global ddnsuser "username"
 - global ddnspass "password"
 - global ddnshost "Host Name"
 
# Define Global Variables
- global ddnsip
 - global ddnslastip
 - if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
 
- global ddnsinterface
 - global ddnssystem ("mt-" . [/system package get system version] )
 
# Define Local Variables
- local int
 
# Loop thru interfaces and look for ones containing # default gateways without routing-marks
- foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
 
 :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
    :global ddnsinterface [/ip route get $int interface]
 } 
}
# Grab the current IP address on that interface.
- global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
 
# Did we get an IP address to compare?
- if ([ :typeof $ddnsip ] = nil ) 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 update required."
 }
}
# End of script
- log info "DDNS: End"