Page 1 of 1

[Changed] Policy routing with dynamic IP's

Posted: Sun Apr 03, 2005 3:19 am
by williamm
Hi,

I need to set up policy routing based on source address of my internal IP's. Some IP's from my internal network should reach Internet using gateway 01 and other internal IP's using gateway 02. The problem is that these two Internet interfaces are PPPoE clients with dynamic IP's. I have created two routing tables corresponding to gateway 01 and 02 and the correct rules but I don't know how could I insert the gateway IP in these tables since they are dynamic addresses (with dynamic gateways also). If I enable the option in PPPoe client to create the default gateway, it's created in the main table.

Is there any way to set up an interface as the gateway in the routing table? IP address is not useful in this case.

Anyone could help me? I'm using 2.8.26 version
I've noticed this problem would happen with any dynamically assigned protocol so if my out interfaces are DHCP clients I get the same problem. Since their IP and gateway is assigned dynamically, there is no possibility to do policy routing because routing tables need that you inform a gateway IP.

If my question is so stupid, please tell me because it really do make sense for me trying to use policy routing with dynamic IP's. Any suggestion is welcome. I've guessed to use a script to create the routing tables on demand (as soon the dynamic routes are created by RouterOS but I don't know if it's possible and how to trigger this script).

Any RouterOS coder read this forum? Maybe questions from newbies are not so relevant :(.

Posted: Mon Apr 04, 2005 3:02 pm
by williamm
Hey Guys,

Am I the only one who has tried to connect a RouterOS into dual PPPoE gateways with dynamic IP´s?

Posted: Tue Apr 05, 2005 2:28 pm
by edzix
you should make a scrit to change the gateways correctly. Assuming that the first pppoe-client is named 'pppoe1' and the second one - 'pppoe2' the script will look as follows (named 'check'):


:global gw1;:global gw2;:global tgw1;:global tgw2
:if ([/system scheduler get routing run-count]<=1) do={
:set gw1 [/interface get [/interface find interface=pppoe1] network]
:set gw2 [/interface get [/interface find interface=pppoe2] network]
}

:set tgw1 [/interface get [/interface find interface=pppoe1] network]
:set tgw2 [/interface get [/interface find interface=pppoe2] network]

:if ($gw1!=$tgw1) do={
/ip policy-routing table 1st set [/ip policy-routing table 1st find \
gateway=$gw1] gateway=$tgw1
}

:if ($gw2!=$tgw2) do={
/ip policy-routing table 2nd set [/ip policy-routing table 2nd find \
gateway=$gw2] gateway=$tgw2
}


Afterwards, add a scheduled task to run this script, for example, each minute:

/system scheduler add name=routing interval=1m on-event=check disabled=no


Edgars