Round robin through multiple interfaces

Solution 1:

I have this setuped at one Ubuntu server machine , I will post the configuration below. It was kind of painful to setup and still there are some problems left , this machine is also providing NAT (on another interface) and for NAT clients some services (openvpn,icq) gets confused when the packets do come from different addresses which changes every now and then.

Anyway: - I've used this to utilize 2x 100 Mbps internet link with two public IPs - works good for apache - every request is handled on different interface and so on ... but the routes for clients gets fixed, so it's kind of good to clear routing cache every once in a while ( by /sbin/route del default)- but then when you do this - some services get confused. (Openvpn clients need to have "float" added to config so they will trust server with multiple addresses and so on ...) . Each connection can get maximum 100 Mbps, but 2 connections can reach 200 Mbps...

Many applications are confused, so when you have a chance to get bonding working - you can administrate switch - I would recommend that approach.

my internet interfaces :

eth0      Link encap:Ethernet  HWaddr 00:11:09:5e:af:af  
          inet addr:69.42.248.102  Bcast:69.42.248.127  Mask:255.255.255.192

eth2      Link encap:Ethernet  HWaddr 00:0e:2e:0d:32:b4  
          inet addr:69.42.248.103  Bcast:69.42.248.127  Mask:255.255.255.192

they are configured by quite default setup in /etc/network/interfaces

auto eth0                                                                                                                       
iface eth0 inet static                                                                                                          
    address 69.42.248.102                                                                                                      
    netmask 255.255.255.192                                                                                                     
    gateway 69.42.248.65                                                                                                       

auto eth2                                                                                                                       
iface eth2 inet static                                                                                                          
    address 69.42.248.103                                                                                                      
    netmask 255.255.255.192                                                                                                     
    gateway 69.42.248.65

and finally I init load balancing by calling a script after startup (add to rc.local (before exit) or crontab)

#!/bin/bash

# I do not remember why this is here multiple times- but I have mutliple gates and interfaces set by default so I guess it's here to clear them all ;-)

/sbin/route del default
/sbin/route del default
/sbin/route del default
/sbin/route del default

ip route add default scope global \                                                                                             
nexthop via 69.42.248.65 dev eth0 weight 1 \                                                                                   
nexthop via 69.42.248.65 dev eth2 weight 1    

This basically tell routing to use same gate with different ethX and same weight - thus doing round-robin per-connection load-balancing.

Solution 2:

The Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical bonded interface.

http://www.cyberciti.biz/tips/linux-bond-or-team-multiple-network-interfaces-nic-into-single-interface.html

http://www.linuxhorizon.ro/bonding.html

http://www.linuxfoundation.org/collaborate/workgroups/networking/bonding