Dynamic DNS Update Script for Hurricane Electric DNS

From MikroTik Wiki
Revision as of 21:51, 26 April 2011 by Saik0 (talk | contribs)
Jump to: navigation, search

This script will update the IP address on (Hurricane Electric DNS service). It updates the A/AAAA record so both IPv4 and IPv6 can be supplied.

It uses the fetch command with the url= parameter. Check that your version of RouterOS -> /tool fetch supports this option.

It uses the following URL to supply update information:

  • For auto IP detection:
  • For manually setting the IP address:

For more information, see this link: [1]

The script:

# Update Hurricane Electric DDNS IPv4 address

:local ddnshost "<dyndnshost>"
:local key "key"
:local updatehost "dyn.dns.he.net"
:local WANinterface "<if>"
:local outputfile ("HE_DDNS" . ".txt")

# Internal processing below...
# ----------------------------------
:local ipv4addr

# Get WAN interface IP address
:set ipv4addr [/ip address get [/ip address find interface=$WANinterface] address]
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]

:if ([:len $ipv4addr] = 0) do={
   :log error ("Could not get IP for interface " . $WANinterface)
   :error ("Could not get IP for interface " . $WANinterface)

:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")

/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" dst-path=$outputfile
:log info ([/file get ($outputfile) contents])
/file remove ($outputfile)