I’ve a static route set up to a PPPoE tunnel connecting to my ISP as the dynamic route to the ISP does not work/have the correct routing mark associated to it. This works fine until the PPPoE reconnects and the gateway changes.
I’d like to have a script check the dynamic route’s gateway and set my static one to match… so far I have this:
:global list “”; :foreach i in [/ip route find] do={:if ([:find [/ip route get $i gateway] “pppoe-out-adsl”]=0) do={:set list ($list . “,” . $i);}}; /ip route print detail without-paging from $list;
without digging into the details of MT scripting I’m a bit lost, I’m sure someone can help me out easily with this.
This might work, assuming you only have 1 dynamic route where the gateway-status contains the string “reachable pppoe-out-adsl-zen”. First, run this command to check. If it comes back with 1, you’re fine. If it comes back with 2 or more, the script will have to be revised:
If that checks out ok, then this script should work:
# tested on RouterOS v4.17
# for the route that contains this comment, do the following
:foreach i in [ /ip route find comment~"Match this route to the Dynamic ADSL" ] do={
# get the gateway of the dynamic adsl route
:local adslGateway [ /ip route get [ find gateway-status~"reachable pppoe-out-adsl-zen" dynamic ] gateway ];
# if the adsl Gateway IP does not match the static gateway IP
if ( $adslGateway != [ /ip route get $i gateway ] ) do={
# set the static gateway to match
/ip route set $i gateway=$adslGateway;
}
}