Community discussions

MikroTik App
 
pedja
Long time Member
Long time Member
Topic Author
Posts: 684
Joined: Sat Feb 26, 2005 5:37 am

How to route on dynamic gateway?

Tue Mar 13, 2007 5:44 pm

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?
 
pedja
Long time Member
Long time Member
Topic Author
Posts: 684
Joined: Sat Feb 26, 2005 5:37 am

Tue Mar 13, 2007 7:45 pm

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?
 
leonj
Frequent Visitor
Frequent Visitor
Posts: 74
Joined: Thu Jun 22, 2006 4:23 pm
Location: South Africa
Contact:

Tue Mar 13, 2007 11:31 pm

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...
 
pedja
Long time Member
Long time Member
Topic Author
Posts: 684
Joined: Sat Feb 26, 2005 5:37 am

Wed Mar 14, 2007 11:04 am

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.
 
changeip
Forum Guru
Forum Guru
Posts: 3833
Joined: Fri May 28, 2004 5:22 pm

Re: How to route on dynamic gateway?

Wed Mar 14, 2007 5:21 pm

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
 
pedja
Long time Member
Long time Member
Topic Author
Posts: 684
Joined: Sat Feb 26, 2005 5:37 am

Sat Mar 17, 2007 10:18 am

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.
 
dana1975
Frequent Visitor
Frequent Visitor
Posts: 94
Joined: Sat Jul 04, 2009 8:32 pm

Re: How to route on dynamic gateway?

Tue Aug 04, 2009 2:38 am

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

Who is online

Users browsing this forum: No registered users and 34 guests