7

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.

Edit: Netmask (as noticed in the comment) is 255.255.254.0 - as I said, they are on the same subnet.

My desire is to utilize both of them with some load balancing. I have tried to follow the advice given in here https://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?

RushPL
  • 169

1 Answers1

2

The only way to have multiple default gateways that I know of is to utilize the methodology shown here: http://lartc.org/howto/lartc.rpdb.multiple-links.html. However one modification I would recommend over this methodology is instead of putting things in /etc/rc.local, store them in network route/rule files (again, this is assuming red hat so YMMV - /etc/sysconfig/network-scripts/route- and /etc/sysconfig/network-scripts/rule-.

To get a single interface to be seen as two interfaces, you could create subinterfaces by following the methodology shown here: http://linux-101.org/howto/create-sub-interfaces-centos-and-redhat

Matthew
  • 2,757