Script - nat ip address changer (SCRNAT-TO-ADDRESS)

Hello fellows, this is my first topic in this vast world of mikrotik, i hope you can help me.

My scenario here at home is:

RB4011
2 ISP WAN (pppoe-out1 / pppoe-out2)
Load Balance PCC / Failover

So my cry for help is:

I need some script to change the IP at /ip firewall nat. I have two ISP but one of them doesnt have the IP address fixed and when the link goes down the IP change and i need to do manually this change! I was using the default MASQUERADE but i need now this way. I tried to change the script at mikrotik wiki ip address changed but doesn’t worked.




There is this explanation about masquerade and scrnat at mikrotik wiki:




This was the original script at mikrotik wiki:

//SCRIPT DO SITE MIKROTIK

:global currentIP;

:local newIP [/ip address get [find interface="ether1"] address];

:if ($newIP != $currentIP) do={
    :put "ip address $currentIP changed to $newIP";
    :set currentIP $newIP;
}

And then this was my first attempt to adapt to my scenario:

:global currentIP;

:local newIP [/ip address get [find interface="pppoe-out2"] address];
:local natIP [/firewall nat get [find comment="NAT VIVO" to-addresses];


:if ($newIP != $natIP) do={
    :put "ip firewall nat $currentIP changed to $natIP";
    :set currentIP $newIP;
}

EDITED:

Hello guys, i discovered some script here at forum and now it’s done my script and running well on PPP profile when the pppoe goes UP again:

:global status [/interface get pppoe-out2 running]
:if ($status) do={
    :global old [/ip firewall nat get [find where comment="NAT VIVO"] to-addresses]
    :global new [/ip address get [find where dynamic=yes and interface="pppoe-out2"] address] 
    :set new [:pick $new 0 [:find $new "/"] ]
    :if ($new != $old) do={
        /ip firewall nat set [find where comment="NAT VIVO"] to-addresses=$new
    }
}

But now i need some script to change the ip at /dude device

Don’t use scheduler, create new PPP profile for PPPoE client and use its on-up event with simple:

/ip firewall nat set [find comment="NAT VIVO"] to-addresses=$"local-address"

Yep, thank u for the help, do you know some way to change the ip at dude device too?

Right now I don’t have Dude on RouterOS, but if the config is accessible from CLI, then it’s the same thing, find the right item by comment/name/whatever and set the address.

searched for commands cli terminal and didnt find anything, the TAB button at terminal stops at some point too =/