Difference between revisions of "Ros3 Dyn DNS"

From CTWUG Wiki
Jump to: navigation, search
(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...)
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
=Info=
 
=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.  
+
There are two scripts available to use. One is for ChangeIP.com or MyDDns.com, and the other for EveryDNS. Once created you should schedule this to run once in a while.  
 +
 
 +
==The ChangeIP.com and MyDDNS.com Script==
 +
 
 +
The :local 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.
 
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==
+
===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.
 
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.
  
Line 10: Line 14:
 
* Routerboard Time Setup, either manually [[rb_time_manual]] or via NTP [[rb_ntp_setup]]
 
* Routerboard Time Setup, either manually [[rb_time_manual]] or via NTP [[rb_ntp_setup]]
  
==Enhancements==
+
===Enhancements===
 
* Check out [[Dynamic DNS Schedule]] to create a schedule, that will run the script at a predefined period.
 
* Check out [[Dynamic DNS Schedule]] to create a schedule, that will run the script at a predefined period.
  
==Script==
+
===Script===
<code>
+
<pre><nowiki>
# Define User Variables
+
# MyDDns International Account
:global ddnsuser "username"
 
:global ddnspass "password"
 
:global ddnshost "Host Name"
 
  
 +
# Local user variables
 +
:local DnsUser "enter your MyDDns username here"
 +
:local DnsPass "enter your MyDDns password here"
 +
:local DnsHost "enter your MyDDns hostname here"
 +
:local DnsInterface "enter your PPPoE interface name here"
  
# Define Global Variables
+
# Global user variables
:global ddnsip
+
# if you have another PPPoE account with this script you need to change LastDnsIpInter to something unique; search/replace
:global ddnslastip
+
:global LastDnsIpInter
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
 
  
:global ddnsinterface
+
:if ([ :typeof $LastDnsIpInter ] = nil) do={ :global LastDnsIpInter "0"}
:global ddnssystem ("mt-" . [/system package get system version] )
 
  
 +
# Get the current Ip Address
 +
:local DnsIp [/ip address get [/ip address find interface=$DnsInterface] address ]
  
  # Define Local Variables
+
# Check for updates
:local int
+
:if ([ :typeof $DnsIp ] = nil ) do={
   
+
  :log info ("DynDns: No Ip address present on ". $DnsInterface )
 +
} else={
 +
  :local NewIp [ :pick $DnsIp 0 [ :find $DnsIp "/" ] ]  
 +
  :if ($NewIp != $LastDnsIpInter) do={
 +
    :log info ("DynDns: ". $DnsInterface ." Sending update.")
 +
    :local DnsResult ( [ :put [ /tool dns-update name=$DnsHost address=$NewIp key-name=$DnsUser key=$DnsPass ] ] )
 +
    :global LastDnsIpInter $NewIp
 +
  } else={
 +
# Uncomment the line below if you want to see when updates aren't needed  
 +
#    :log info "DynDns: ($DnsInterface) No update needed"
 +
  }
 +
}
 +
</nowiki></pre>
  
# Loop thru interfaces and look for ones containing
+
==The EveryDNS.com Script==
# default gateways without routing-marks
+
Change all the local variables at the top of the script to your relevant EveryDNS account. This script can work with multiple interfaces. You need to setup a script for every interface. Change the edlastip1 global variable to edlastip2 for the second script, and edlastip3 for the third script etc.
: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={
+
<pre><nowiki>
    :global ddnsinterface [/ip route get $int interface]
+
# Define user variables
  }
+
# Please NOTE that your username and password will be sent cleartext across the internet!
}
+
:local eduser "enter your EveryDNS username here"
 +
:local edpass "enter your EveryDNS password here"
 +
:local eddomain "enter your full qualifying domain here"
 +
:local edinterface "enter the interface which you want to grab the IP from"
 +
 
 +
# Change this global variable if you want more than 1 script
 +
:global edlastip1
 +
:local str
 +
:local edip
 +
:local ip
 +
 
 +
:if ([ :typeof $edlastip1 ] = nil ) do={ :global edlastip1 "0" }
  
# Grab the current IP address on that interface.
+
:local edip [ /ip address get [/ip address find interface=$edinterface ] address ]
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
 
 
  
# Did we get an IP address to compare?
+
:if ([ :typeof $edip ] = nil ) do={
:if ([ :typeof $ddnsip ] = nil ) do={
+
   :log info ("EveryDNS: No ip address on $edinterface .")
   :log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
 
 
} else={
 
} else={
 
  
   :if ($ddnsip != $ddnslastip) do={
+
# strip off netmask correctly (MRz)
+
  :for i from=( [:len $edip] - 1) to=0 do={
 +
      :if ( [:pick $edip $i] = "/") do={
 +
  :set edip [:pick $edip 0 $i];
 +
      }
 +
  }
 +
 
 +
   :if ($edip != $edlastip1) do={
  
     :log info "DDNS: Sending UPDATE!"
+
     :log info ("EveryDNS: $eddomain -> $edip")
     :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
+
# use url directly and mode http (MRz)
     :global ddnslastip $ddnsip
+
     :local str "/index.php?ver=0.1&ip=$edip&domain=$eddomain"
+
    /tool fetch url="http://dyn.everydns.net/$str" mode=http user=$eduser password=$edpass dst-path=("/EveryDNS.".$eddomain)
 +
     :delay 1
  
  } else={
+
# output any error messages received from file
     :log info "DDNS: No update required."
+
    :local str [/file find name="EveryDNS.$eddomain"];
 +
     :log info [/file get $str contents];
 +
    /file remove $str
 +
    :global edlastip1 $edip
 
   }
 
   }
+
}
 +
</nowiki></pre>
  
}
+
Add a schedule to run this script every minute. It will only update the IP if it differs with the current domain IP.
+
 
 +
==The Freedns.afraid.org Script==
 +
 
 +
Get your direct url from your freedns.afraid.org domain by logging into your account and clicking on the Dynamic DNS link on the left. If you have previously configured an A host for a particular subdomain, you will see your available dynamic dns addresses on the right.It will look something like this
 +
 
 +
<pre><nowiki>
 +
http://freedns.afraid.org/dynamic/update.php?Umx2TmFFTVRTTJTRTQVA4bm53bzo0MTIzODA2
 +
 
 +
Now use that link to update your ip from within ROS with the following command:
 +
 
 +
/tool fetch address="freedns.afraid.org" host="freedns.afraid.org" mode=http src-path="dynamic/update.php\?Umx2TmFFTVRTTJTRTQVA4bm53bzo0MTIzODA2" keep-result=no
 +
 
 +
'''NOTE !!!!'''
  
# End of script
+
The \ just after the dynamic/update.php is correct. You need to add that for this command to work properly.
:log info "DDNS: End"
+
From the above scripts , you can modify this to make an automatic update script.
  
</code>
+
</nowiki></pre>

Latest revision as of 23:46, 21 January 2010

Info

There are two scripts available to use. One is for ChangeIP.com or MyDDns.com, and the other for EveryDNS. Once created you should schedule this to run once in a while.

The ChangeIP.com and MyDDNS.com Script

The :local 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.

Enhancements

  • Check out Dynamic DNS Schedule to create a schedule, that will run the script at a predefined period.

Script

# MyDDns International Account

# Local user variables
:local DnsUser "enter your MyDDns username here"
:local DnsPass "enter your MyDDns password here"
:local DnsHost "enter your MyDDns hostname here"
:local DnsInterface "enter your PPPoE interface name here"

# Global user variables
# if you have another PPPoE account with this script you need to change LastDnsIpInter to something unique; search/replace
:global LastDnsIpInter

:if ([ :typeof $LastDnsIpInter ] = nil) do={ :global LastDnsIpInter "0"}

# Get the current Ip Address
:local DnsIp [/ip address get [/ip address find interface=$DnsInterface] address ]

# Check for updates
:if ([ :typeof $DnsIp ] = nil ) do={
  :log info ("DynDns: No Ip address present on ". $DnsInterface )
} else={
  :local NewIp [ :pick $DnsIp 0 [ :find $DnsIp "/" ] ]  
  :if ($NewIp != $LastDnsIpInter) do={
    :log info ("DynDns: ". $DnsInterface ." Sending update.")
    :local DnsResult ( [ :put [ /tool dns-update name=$DnsHost address=$NewIp key-name=$DnsUser key=$DnsPass ] ] )
    :global LastDnsIpInter $NewIp
  } else={
# Uncomment the line below if you want to see when updates aren't needed  
#    :log info "DynDns: ($DnsInterface) No update needed"
  }
}

The EveryDNS.com Script

Change all the local variables at the top of the script to your relevant EveryDNS account. This script can work with multiple interfaces. You need to setup a script for every interface. Change the edlastip1 global variable to edlastip2 for the second script, and edlastip3 for the third script etc.

# Define user variables
# Please NOTE that your username and password will be sent cleartext across the internet!
:local eduser "enter your EveryDNS username here"
:local edpass "enter your EveryDNS password here"
:local eddomain "enter your full qualifying domain here"
:local edinterface "enter the interface which you want to grab the IP from"

# Change this global variable if you want more than 1 script
:global edlastip1
:local str
:local edip
:local ip

:if ([ :typeof $edlastip1 ] = nil ) do={ :global edlastip1 "0" }

:local edip [ /ip address get [/ip address find interface=$edinterface ] address ]

:if ([ :typeof $edip ] = nil ) do={
   :log info ("EveryDNS: No ip address on $edinterface .")
} else={

# strip off netmask correctly (MRz)
   :for i from=( [:len $edip] - 1) to=0 do={
      :if ( [:pick $edip $i] = "/") do={
	   :set edip [:pick $edip 0 $i];
      }
   }

  :if ($edip != $edlastip1) do={

    :log info ("EveryDNS: $eddomain -> $edip")
# use url directly and mode http (MRz)
    :local str "/index.php?ver=0.1&ip=$edip&domain=$eddomain"
    /tool fetch url="http://dyn.everydns.net/$str" mode=http user=$eduser password=$edpass dst-path=("/EveryDNS.".$eddomain)
    :delay 1

# output any error messages received from file
    :local str [/file find name="EveryDNS.$eddomain"];
    :log info [/file get $str contents];
    /file remove $str
    :global edlastip1 $edip
  }
}

Add a schedule to run this script every minute. It will only update the IP if it differs with the current domain IP.

The Freedns.afraid.org Script

Get your direct url from your freedns.afraid.org domain by logging into your account and clicking on the Dynamic DNS link on the left. If you have previously configured an A host for a particular subdomain, you will see your available dynamic dns addresses on the right.It will look something like this

http://freedns.afraid.org/dynamic/update.php?Umx2TmFFTVRTTJTRTQVA4bm53bzo0MTIzODA2

Now use that link to update your ip from within ROS with the following command:

/tool fetch address="freedns.afraid.org" host="freedns.afraid.org" mode=http src-path="dynamic/update.php\?Umx2TmFFTVRTTJTRTQVA4bm53bzo0MTIzODA2" keep-result=no

'''NOTE !!!!'''

The \ just after the dynamic/update.php is correct. You need to add that for this command to work properly.
From the above scripts , you can modify this to make an automatic update script.