Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to alternative between networking interfaces to a particular ip. For example:

Request to 192.168.1.5 // uses interface 1

Request to 192.168.1.5 // uses interface 2

Request to 192.168.1.5 // uses interface 1

Request to 192.168.1.5 // uses interface 2

Request to 192.168.1.5 // uses interface 1

Request to 192.168.1.5 // uses interface 2

I'm using Ubuntu 10. I found this:

http://www.go2linux.org/load-balance-traffic-for-two-isps-with-linux

Is that the sort of thing I'm looking for?

share|improve this question
    
What is it you are trying to accomplish? Are the two NICs on the same box and you want traffic going in/out to go through the 1.5 address but use both NICs? Or do you have two machines and you want to load balance between them? Also, what is being hosted on the machine(s) you are trying to access at that ip? –  Cypher Oct 27 '10 at 1:47
add comment

3 Answers

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

share|improve this answer
    
What I can't seem to tell from these links is whether or not from the external POV (192.168.1.5) does it see a request coming from 1 IP or 1 per interface? We (i'm with the original poster) specifically want multiple IPs –  bjeanes Oct 18 '10 at 6:07
    
@bjeanes bonding would produce one interface (eg bond0) with one IP. What it sounds like you need to do is have your client bind() to the IP you want to use before you call connect(). If you didn't write the client/have access to the source to change the client, then things get tougher. –  DerfK Oct 27 '10 at 3:40
add comment

My DNS is rusty, but can't you just put two ip addresses in your A record and most systems will alternate between the two, if I remember right. Of course that assumes you're using a hostname and not a direct ip.

share|improve this answer
    
Your statement is correct, but I do not think thats what he wants to do. –  Jacob Jan 30 '11 at 2:32
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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