Hi
I have two ISP lines on which i have successfully load balanced the
outgoing traffic.
-----------------------------------------
pfctl -f loadb.conf
-----------------------------------------

"loadb.conf"

lan_net = "10.0.0.0/24"
int_if = "mtd0"
ext_if0 = "ne3"
ext_gw0 = "192.168.1.1"
ext_if1 = "ne4"
ext_gw1 = "192.168.2.1"

nat on $ext_if0 from $lan_net to any -> ($ext_if0)
nat on $ext_if1 from $lan_net to any -> ($ext_if1)

pass out on $int_if from any to $lan_net
pass in quick on $int_if from $lan_net to $int_if

pass in on $int_if route-to \
{($ext_if0 $ext_gw0),($ext_if1 $ext_gw1)} round-robin \
proto tcp from $lan_net to any flags S/SA modulate state

pass in on $int_if route-to \
{($ext_if0 $ext_gw0),($ext_if1 $ext_gw1)} round-robin \
proto { udp, icmp } from $lan_net to any keep state

pass out on $ext_if0 proto tcp from any to any flags S/SA modulate state
out on $ext_if0 proto { udp, icmp } from any to any keep state
pass out on $ext_if1 proto tcp from any to any flags S/SA modulate state
out on $ext_if1 proto { udp, icmp } from any to any keep state

pass out on $ext_if0 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any
pass out on $ext_if1 route-to ($ext_if0 $ext_gw0) from $ext_if0 to any


In case one line goes down then all the traffic routed to other line means
now, pfctl uses other file depends on the working line (eg:- ISP1_pf.conf
or ISP2_pf.conf ) that include rules for single line support.
------------------------------------------------------------------------
pfctl -f ISP1_pf.conf
or
pfctl -f ISP2_pf.conf
-------------------------------------------------------------------------

"ISP2_pf.conf"

lan_net = "10.0.0.0/24"
int_if = "mtd0"
ext_if0 = "ne3"
ext_gw0 = "192.168.2.1"
nat on $ext_if0 from $lan_net to any -> ($ext_if0)
pass out on $int_if from any to $lan_net
pass in quick on $int_if from $lan_net to $int_if

pass in on $int_if route-to ($ext_if0 $ext_gw0) proto tcp \
from $lan_net to any flags S/SA modulate state
pass in on $int_if route-to ($ext_if0 $ext_gw0) proto tcp \
proto { udp, icmp } from $lan_net to any keep state
pass out on $ext_if0 proto tcp from any to any flags S/SA modulate state
out on $ext_if0 proto { udp, icmp } from any to any keep state


default gateway i set is 192.168.1.1 (IP of ISP1 modem).

Now, problem is that if Line1 goes down then link to internet goes down
besides the pfctl uses rules file of ISP2 i.e. ISP2_pf.conf.

I know this is happenning because of default gateway is still 192.168.1.1.
Now,when i am changing the default gateway to 192.168.2.1( IP of ISP2
modem) and
execute sh /etc/netstart then it works fine.

Actually, i need to make all this process dynamic that's why i need to
change gateway dynamically.

What i have tried so far to do so are as follows :-

I am trying to change default gateway using filehandling in perl but it
does not works.I know this not the right way to do so but i have tried it.

gateway.pl
---------------------------------------------------------------------------
open(GATEWAY,">/etc/mygate");
print GATEWAY"192.168.2.1";
close(GATEWAY);
system("sh /etc/netstart");
----------------------------------------------------------------------
i have also tried with route command using -mpath option but failed to
solve my problem.
----------------------------------------------------------
route add 0/0 -mpath 192.168.2.1
-----------------------------------------------------------
So,please tell me how can i set multiple default gateways or suggest me
any other way to set mutiple gateways for same destination or how to make
other gateway available if one goes down.

Thanks
Vikrant

Reply via email to