mikrotik DDNS

1. Script for DDNS

Create the following script with name TanDNS and the following permissions write, test, read, policy

# Tanshu automatic DNS updates

# User account info
:local user "user"
:local pass "123456"

# Set the hostname or label of network to be updated.
:local host "home.tanshu.com"

# Change to the name of interface that gets the changing IP address
: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 "TanDNS: 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://bifrost.tanshu.com/update\3Fdomain=$host"
        :log info "TanDNS: Sending update for $host"
        /tool fetch url=$url user=$user password=$pass mode=http keep-result=no
        :log info "TanDNS: Host $host updated on TanDNS with IP $currentIP"
    }  else={
        :log info "TanDNS: Previous IP $previousIP and current IP equal, no update need"
} else={
    :log info "TanDNS: $inetinterface is not currently running, so therefore will not update."

2. Schedule the script

Create the following schedule with name TanDNS-Update and the following permissions write, test, read, policy, 5 minute interval and TanDNS On Event.