Community discussions

MikroTik App
 
artisan1
just joined
Topic Author
Posts: 3
Joined: Sun Jan 30, 2022 6:42 am

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

Sat Feb 05, 2022 4:05 pm

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.

Image


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

Image


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

Image
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Script - nat ip address changer (SCRNAT-TO-ADDRESS)  [SOLVED]

Sat Feb 05, 2022 9:19 pm

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"
 
artisan1
just joined
Topic Author
Posts: 3
Joined: Sun Jan 30, 2022 6:42 am

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

Mon Feb 07, 2022 7:26 am

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?
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

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

Mon Feb 07, 2022 2:08 pm

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.
 
artisan1
just joined
Topic Author
Posts: 3
Joined: Sun Jan 30, 2022 6:42 am

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

Mon Feb 07, 2022 9:41 pm

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 =/

Who is online

Users browsing this forum: No registered users and 12 guests