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

Edit: Netmask (as noticed in the comment) is - 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

ip route show table main | grep -Ev '^default' \                                                                                                                                                                                 
   | while read ROUTE ; do                                                                                                                                                                                                       
     ip route add table ISP1 $ROUTE                                                                                                                                                                                              
ip route add default via table ISP1                                                                                                                                                                                
ip route add default via 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 Shouldn't the packets change routes in a random manner? How to debug it?

  • 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 then they are on different networks... – Mark Henderson Jun 4 '12 at 22:31
  • Netmask is exactly as you have guessed. I have updated the question. Sorry for confusion. – RushPL Jun 4 '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 weight 1 nexthop via weight 1? Is there some reason why you are trying to do the MARK with iptables? – Zoredache Jun 4 '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 5 '12 at 19:41

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.