Page 1 of 1
How to route on dynamic gateway?
Posted: Tue Mar 13, 2007 5:44 pm
by pedja
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?
Posted: Tue Mar 13, 2007 7:45 pm
by pedja
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?
Posted: Tue Mar 13, 2007 11:31 pm
by leonj
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.
Hope it helps...
Posted: Wed Mar 14, 2007 11:04 am
by pedja
It changes each time when ip changes. When, I do not know, it may change anytime.
Netwatch checks if IP is pingable. Problem is, MT can ping IP's regardless this interface because it has two interfaces leading to internet.
Re: How to route on dynamic gateway?
Posted: Wed Mar 14, 2007 5:21 pm
by changeip
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 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 : ) )
Sam
Posted: Sat Mar 17, 2007 10:18 am
by pedja
I already thought about it, but inability to specifu interface, killed the idea
I solved a problem in most painfull way: i asked for static IP.
This is an issue MT stuff should pay atention to.
Re: How to route on dynamic gateway?
Posted: Tue Aug 04, 2009 2:38 am
by dana1975
hi dear pedja
i tested your script but i think it had a probleb
this code return network ip, but we want to use ip address of connection
:set mGateway [get $mAddress network] ;
also i have another question
do you change you command that we use it in load balancing?
thank you so much