I’m currently using internet service from my ISP which is using dynamic IP, due to nature of dynamic IP, it difficult to access my network from internet if my modem rebooted, I know there are already tricks to access network from internet by using VPN as tunnel. My question is, is anybody here have scripts to grab current public IP from IP cloud, and use that IP to auto generate new dstnat and remove previous dstnat and send that information through telegram.
Am not really sure i ve understood what you want to achieve…
The cloud will auto update when a change to the Public IP is detected…
What dst nat you mean ?
MikroTik DDNS service didn’t work for me, each time ISP changed the address, MTiK service didn’t update it.
I created a script (below), it’s running every 5 minutes and sending an email with OLD and NEW IP address
delay 5;
:if ([:len [/file find name=currentIP.txt]] = 0) do={
:local myfile "currentIP.txt";
/file print file=$myfile;
:delay 3;
:local cont "1.1.1.1";
/file set $myfile contents=$cont;
}
:if ([:len [/file find name=currentIP.txt]] > 0) do={
:local filename "currentIP.txt";
:local ip [/file get currentIP.txt contents];
:delay 1;
:local cip ([:resolve myip.opendns.com server=208.67.222.222]);
:delay 1;
:local sub ("New WAN address: $cip");
:local bod ("old WAN IP = $ip new WAN IP = $cip");
:delay 3;
:if ($ip != $cip) do={/tool e-mail send to="YOUR.EMAIL@gmail.com" subject="$sub" body="$bod";
:delay 4;
/file set $filename contents=$cip;
}
}
Pick IP From Route (add WAN to your WAN connection name. ie. ether1-WAN)
:global Stat [/ip route get [find gateway~“WAN”] pref-src]
Pick IP from Address (add WAN to your WAN connection name. ie. ether1-WAN)
:global OnEtherSub [/ip address get [find interface~“WAN”] address]
:global OnEther [:pick $OnEtherSub 0 [:find $OnEtherSub “/”]]
Pick IP from DHCP-Client (add WAN to your WAN connection name. ie. ether1-WAN)
:global OnEtherSub [/ip dhcp-client get [find interface~“WAN”] address]
:global OnEther [:pick $OnEtherSub 0 [:find $OnEtherSub “/”]]
Get Public IP from IP Cloud
:global ipCloud [/ip cloud get public-address]
IP Cloud will update properly if your device has public IP. If MT is behind another router, you can force a periodic update using ddns-update-interval. No scripting required.
/ip cloud
set ddns-enabled=yes ddns-update-interval=10m
Also, no scripting required for dstnat entries. Assuming you currently have set dst-address instead of in-interface(-list) to be able to reach your servers from inside, you can use dst-address-type=local instead.