Utilize two gateways on the same network same interface with load balancing

Posted by RushPL on Server Fault See other posts from Server Fault or by RushPL
Published on 2012-06-04T17:00:23Z Indexed on 2012/06/04 22:42 UTC
Read the original article Hit count: 231

My setup is two ISPs on a single interface and single network. I can either set my default gateway to 192.168.0.1 or 192.168.1.250 and either work.

My desire is to utilize both of them with some load balancing. I have tried to follow the advice given in here http://serverfault.com/a/96586

#!/bin/sh                                                                                                                                                                                                                        
ip route show table main | grep -Ev '^default' \                                                                                                                                                                                 
   | while read ROUTE ; do                                                                                                                                                                                                       
     ip route add table ISP1 $ROUTE                                                                                                                                                                                              
done                                                                                                                                                                                                                             
ip route add default via 192.168.1.250 table ISP1                                                                                                                                                                                
ip route add default via 192.168.0.1 table ISP2                                                                                                                                                                                  

iptables -t mangle -A PREROUTING -j CONNMARK --restore-mark                                                                                                                                                                      
iptables -t mangle -A PREROUTING -m mark ! --mark 0 -j ACCEPT                                                                                                                                                                    
iptables -t mangle -A PREROUTING -j MARK --set-mark 10                                                                                                                                                                           
iptables -t mangle -A PREROUTING -m statistic --mode random --probability 0.5 -j MARK --set-mark 20                                                                                                                              
iptables -t mangle -A PREROUTING -j CONNMARK --save-mark

Now then I do "traceroute somehost" repeatedly I can only get route through my default route which is 192.168.1.250. Shouldn't the packets change routes in a random manner? How to debug it?

© Server Fault or respective owner

Related posts about iptables

Related posts about load-balancing