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
  • 6
  • You say they're both on the same network, and yet you have one on `.0.1` and one on `.1.250` - unless you have a subnet mask less than or equal to `255.255.254.0` then they are on different networks... – Mark Henderson Jun 04 '12 at 22:31
  • Netmask is exactly as you have guessed. I have updated the question. Sorry for confusion. – RushPL Jun 04 '12 at 22:52
  • 1
    Why didn't you just use something like this to add a default gateway to the main table that will distribute between the two gateways? `ip route add default scope global nexthop via 192.168.1.250 weight 1 nexthop via 192.168.0.1 weight 1`? Is there some reason why you are trying to do the MARK with iptables? – Zoredache Jun 04 '12 at 23:38
  • What's your use case for load balancing between the two ISPs ? Unless both ISPs are announcing the same public addresses, it could cause undesirable results constantly switching packet paths for certain data types. For example, some online services maintain 'session' based on the remote ip. If this is constantly changing it will create a new session for each ip, or randomly deny the ip which didn't start the original session. – Ashley Jun 05 '12 at 19:41

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,666
  • 8
  • 32
  • 50