This is script that I made, Hope it will help you... You can update DDNS via main wan or via specific PPPoE/L2TP/Ethernet/Lte etc,,,..
# Script name (must be same as you called the script)
:local ScriptName "dDNS"
# Define dynamic hosts [example 'INTERFACE|PROVAIDER@DYNAMICHOST' (via interface), example 'PROVAIDER@DYNAMICHOST' (via default gateway/interface)]
:local Hosts "dyndns@yourdomain.dyndns.net,dynu@yourdomain.dynu.net,lte1|dynu@yourdomain2.dynu.net"
# Define accounts [example 'provaider|username@password']
:local Accounts "dyndns|USERNAME@PASSWORD,dynu|USERNAME@PASSWORD"
:if ([:len [/system script job find script=$ScriptName]]>1) do={:error "Another copy of $ScriptName is running.";}
:global UpdateDNS do={
:local wan $5;
:local dynprov $1;
:local dynaddr $2;
:local dynuser $3;
:local dynpass $4;
:local dynhost;
:local dynurlv;
:if ($dynprov="dynu") do={
:set dynhost "api.dynu.com";
:set dynurlv "/nic/update?hostname=$dynaddr";
}
:if ($dynprov="dyndns") do={
:set dynhost "members.dyndns.org";
:set dynurlv "/nic/update?hostname=$dynaddr&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG";
}
:if (([:len $dynprov]=0) && ([:len $dynaddr]=0) && ([:len $dynuser]=0) && ([:len $dynpass]=0)) do={
:error "example: \$UpdateDNS <provaider> <domain> <username> <password> <interface>\r\n<provaider> dyndns dynu\r\n<domain> mydomain.dyndns.org\r\n<username> your username\r\n<password> your password\r\n<interface> send update by another interface such lte1\r\n";
} else={
:if (([:len $dynprov]=0) || ([:len $dynhost]=0)) do={:error "Provaider wan't set or not supported\r\n"}
:if ([:len $dynaddr]=0) do={:error "Dynamic domain was not set\r\n"}
:if ([:len $dynuser]=0) do={:error "Username was not set\r\n"}
:if ([:len $dynpass]=0) do={:error "Password was not set\r\n"}
}
:local ReadFile do={
:local dynfile $1;
:local dynaddr [:pick $dynfile ([:find $dynfile "."]+1) [:len $dynfile]];
:local dynprov [:pick $dynfile 0 [:find $dynfile "."]];
:local ipaddr;
:if ([:len [/file find name=$dynfile]]>0) do={
:local dyndata [file get $dynfile contents];
:if ($dynprov="dyndns") do={
:set $ipaddr [:pick $dyndata ([:find $dyndata " "]+1) [:len $dyndata]];
}
:if ($dynprov="dynu") do={
:set $ipaddr [:resolve $dynaddr];
}
:if ([:pick $dyndata [:find $dyndata "nochg"] 5]="nochg") do={
:log info ("<$dynprov> '".$dynaddr."' already updated ($ipaddr) ...");
} else={
:log warning ("<$dynprov> '".$dynaddr."' updated ($ipaddr) ...");
}
} else={
:set $ipaddr [:resolve $dynaddr];
:log warning ("<$dynprov> '".$dynaddr."' has been set ($ipaddr) ...");
}
:return $ipaddr;
}
:set dynhost [:resolve $dynhost];
:local WanToIp do={
:if ([:len [/ip dhcp-client find where interface=[:tostr $1]]]>0) do={
:return [/ip dhcp-client get [find interface=[:tostr $1]] gateway];
} else={
:return [$1];
}
}
:local RunOnHostDown do={
:if ($1!=false) do={
:local ipaddr [:tostr $1];
:local ondown [:tostr $2];
:local wan [:tostr $3];
:local desc [:tostr $4];
# If host already not response set delay 10 minutes before run script
:if ([/ping $ipaddr count=3]=0) do={
:if ([:len $wan]>0) do={
:if ([/interface get value-name=type $wan]="lte") do={
/system routerboard usb power-reset duration=10s
}
:if ([:pick [/interface get value-name=type $wan] ([:find [/interface get value-name=type $wan] "-"]+1) [:len [/interface get value-name=type $wan]]]="out") do={
/interface disable $wan;
:delay 200ms;
/interface enable $wan;
}
}
:set $ondown ("/log error \"retry update dynamic dns in 10 minutes.\"\r\n/delay 10m\r\n".$ondown);
}
# Create netwatch per hosts, if not exists
:if ([:len [/tool netwatch find where host=$ipaddr]]=0) do={
/tool netwatch add host=$ipaddr down-script=$ondown
/tool netwatch set down-script=("/tool netwatch remove ".[/tool netwatch find where host=$ipaddr]."\r\n\r\n".[/tool netwatch get value-name=down-script [/tool netwatch find where host=$ipaddr]]) [/tool netwatch find where host=$ipaddr]
:log info ("'$ipaddr' netwatch has been created by script.");
} else={
# Set netwatch self remove, if not exists
:if ([:typeof [:find [/tool netwatch get value-name="down-script" [/tool netwatch find host=$ipaddr]] ("/tool netwatch remove ".[/tool netwatch find where host=$ipaddr])]]="nil") do={
/tool netwatch set down-script=("/tool netwatch remove ".[/tool netwatch find where host=$ipaddr]."\r\n".[/tool netwatch get value-name=down-script [/tool netwatch find where host=$ipaddr]]) [/tool netwatch find where host=$ipaddr]
}
# Set append on-down event (run script)
:if ([:typeof [:find [/tool netwatch get value-name="down-script" [/tool netwatch find host=$ipaddr]] $ondown]]="nil") do={
/tool netwatch set down-script=([/tool netwatch get value-name="down-script" [/tool netwatch find host=$ipaddr]].$ondown) [/tool netwatch find host=$ipaddr];
}
}
# Set log 'error' when host is down
:if ([:typeof [:find [/tool netwatch get value-name="down-script" [/tool netwatch find host=$ipaddr]] $desc]]="nil") do={
/tool netwatch set down-script=(("/log error \"'$desc' was down.\"\r\n").[/tool netwatch get value-name="down-script" [/tool netwatch find host=$ipaddr]]) [/tool netwatch find host=$ipaddr];
}
:if ([:typeof [:find [/tool netwatch get value-name="comment" [/tool netwatch find host=$ipaddr]] $desc]]="nil") do={
:if ([:len [/tool netwatch get value-name="comment" [/tool netwatch find host=$ipaddr]]]>0) do={
/tool netwatch set comment=([/tool netwatch get value-name="comment" [/tool netwatch find host=$ipaddr]].", '$desc'") [/tool netwatch find host=$ipaddr]
} else={
/tool netwatch set comment=("watching for dynamic hosts '$desc'") [/tool netwatch find host=$ipaddr]
}
}
}
}
:local AddSchedulerPerHost do={
:local schname [:tostr $1];
:local schcode [:tostr $2];
:local schtime 3600;
:if ([:len [/system scheduler find name=$schname]]=0) do={
/system scheduler add interval=$schtime on-event=$schcode comment=("check dynamic dns proviaders for updates every ".($schtime/60)." minutes.") name=$schname
} else={
:if ([:typeof [:find [/system scheduler get value-name="on-event" [/system scheduler find where name=$schname]] $schcode]]="nil") do={
/system scheduler set interval=$schtime on-event=([/system scheduler get value-name=on-event $schname].$schcode) [/system scheduler find where name=$schname]
}
}
}
:log info ("<$dynprov> Update '".$dynaddr."' ...");
:if (([:len [/interface find name=$wan]]>0) && ([/interface get value-name=disabled $wan]=no)) do={
/ip route add distance=1 gateway=[$WanToIp $wan] dst-address=$dynhost comment="updating '$dynaddr' via '$wan'"
:delay 800ms;
}
/tool fetch address=$dynhost src-path=$dynurlv mode=http user=$dynuser password=$dynpass dst-path=("$dynprov.".$dynaddr)
/ip route remove [/ip route find where comment="updating '$dynaddr' via '$wan'"]
$RunOnHostDown [$ReadFile ("$dynprov.".$dynaddr)] ("/log error (\"<$dynprov> '$dynaddr' is offline (netwatch) ...\");\r\n\$UpdateDNS $dynprov $dynaddr $dynuser $dynpass $wan\r\n\r\n") $wan $dynaddr;
$AddSchedulerPerHost "UpdateDNS" ("/log info (\"<$dynprov> Update '$dynaddr' by scheduler ...\");\r\n\$UpdateDNS $dynprov $dynaddr $dynuser $dynpass $wan\r\n\r\n");
}
:foreach Host in=[:toarray $Hosts] do={
:local wan;
:local dynprov;
:local dynaddr;
:local dynuser;
:local dynpass;
:if ([:len [:pick $Host (-1) ([:find $Host "|"])]]>0) do={
:set wan [:pick $Host 0 ([:find $Host "|"])];
:set dynprov [:pick $Host ([:find $Host "|"]+1) [:find $Host "@"]];
:set dynaddr [:pick $Host ([:find $Host "@"]+1) [:len $Host]];
} else={
:set dynprov [:pick $Host 0 [:find $Host "@"]];
:set dynaddr [:pick $Host ([:find $Host "@"]+1) [:len $Host]];
}
:if ([:len [:pick $Accounts (-1) ([:find $Accounts "|"])]]>0) do={
:foreach account in=[:toarray $Accounts] do={
:if ([:pick $account 0 [:find $account "|"]]=$dynprov) do={
:set dynuser [:pick $account ([:find $account "|"]+1) [:find $account "@"]];
:set dynpass [:pick $account ([:find $account "@"]+1) [:len $account]];
}
}
} else={
:set dynuser [:pick $Accounts 0 [:find $Accounts "@"]];
:set dynpass [:pick $Accounts ([:find $Accounts "@"]+1) [:len $Accounts]];
}
:put ("\$UpdateDNS $dynprov $dynaddr $dynuser $dynpass $wan");
$UpdateDNS $dynprov $dynaddr $dynuser $dynpass $wan;
}