I have strange situation. I connect to ISP via PPPoE. I get dynamic public IP but also gateway address on that connection changes. This link is one of two I use for internet connection.
I’ve build simple load balancing by route marking connections of some client IP’s and routing them via one or other link. Everything works fine, until this PPPoE connection reconnects, and I get another IP and another gateway. ALl my routing settings became obsollete.
Is there a way in MT to handle this, i mean, to change routing for route marked connections to new gateway?
I’ve created script that should help solving a problem. It checks gateway of specified interface ($mInterface), looks for default routing rule that matches specified route mark ($mRoutingMark) and alters rule’s gateway to match the one set for interface. If default routing rule does not exist, script creates it.
# name of interface that should be monitored
# (edit to match your interface name)
:set mInterface pppoe-adsl ;
# routing mark name used for default route that should be updated
# (edit to match your routing mark name)
:set mRoutingMark adsl-user ;
/ip address ;
:set mAddress [find interface=$mInterface] ;
:set mGateway [get $mAddress network] ;
/ip route ;
:set mGatewayFound 0
:foreach i in [find routing-mark=$mRoutingMark] do={ \
:set mDstAddress [get $i dst-address]; \
:set qResult [:find $mDstAddress "0.0.0.0/0"]; \
:if ($qResult = 0) do={ \
set $i gateway=$mGateway ; \
:put "gateway rule adjusted"; \
:set mGatewayFound 1; \
}; \
};
:if ($mGatewayFound = 0) do={ ; \
add dst-address=0.0.0.0/0 gateway=$mGateway routing-mark=$mRoutingMark; \
:put "gateway rule added"; \
};
Question is, how to run this script other that scheduler? Is there a way that IP change on interface can triger this script?
How often does the gateway IP change? Consider Netwatch. You could place a script there that fire’s off your script that modifies the routing marks, and also then changes the netwatch to “watch” the correct gateway again.
I believe you can use routing filters, in the dynamic-in chain, to say ‘the learned default gateway should get this route-mark’. This works excellent except for the fact you can’t tell the routing filter which interface you want it to run on… so it applies to every dynamically learned gateway (MT, please add this option : ) )