It is useful to manage load balancing and failover to have an high availablity network.
First we need to install ifenslave-2.6:
apt-get install ifenslave-2.6
Then add a bonding module configuration file into /etc/modprobe.d/
cd /etc/modprobe.d/ touch aliases-bond
and configure the module by editing (VI) the /etc/modprobe.d/aliases-bond file and adding these two lines:
alias bond0 bonding options bond0 mode=0 miimon=200
Where bond0 is the bonding aggreggation name. You could imagine to configure more aggregats to match your specific needs with several network interfaces.
I personaly tested each modes (0-6) and the mode 0 was choosed because it matches my needs:
and others discarded (e.g mode 6) because the failover mode failed during testing or the load-balancing was not evident. For more informations on “mode” you can have a look at http://www.linuxhorizon.ro/bonding.html.
The configuration above uses this method by setting miimon=200.
(The next part was originaly explained by http://www.howtoforge.com/nic_bonding )
Using 'mii-tool' you should see something like the following:
testbox:/# mii-tool eth0: negotiated 100baseTx-FD, link ok eth1: negotiated 100baseTx-FD, link ok
In order for this to work, the kernel must have support for bonding devices. A few ways to check would be:
testbox:/# modprobe --list | grep bonding/lib/modules/22.214.171.124-vs2.0/kernel/drivers/net/bonding/bonding.ko testbox:/# cat /boot/config-126.96.36.199-vs2.0 | grep -i bonding CONFIG_BONDING=m
We use the mii-tool (mii.o module) to monitor the interfaces for failover… though, as most ethernet adapters use an MII (Media Independant Interface) to autonegotiate link speeds, its pretty standard that you'd have this.
testbox:/# cat /boot/config-188.8.131.52-vs2.0 | grep -i mii# CONFIG_MPENTIUMII is not set # CONFIG_MPENTIUMIII is not set CONFIG_MII=y testbox:/# modprobe --list | grep -i mii /lib/modules/2.4.26-2-686/kernel/drivers/net/mii.ko
: what about the two options:
For this method you have to garanty either a reliable host/firewall/router… because it will ping it in order to define if the interface is up or not! This is not the best choice! First if you ping a firewall and the “echo” protocols is not allowed, then your network cards will be turned of and this is also the case if you ping a host that is turned off or his network card is down!!!!
To use this method, you have to replace the “miimon” option by the arp options. This will produce a module configuration like:
alias bond0 bonding options bond0 mode=0 arp_interval=2000 arp_ip_target=184.108.40.206
In this example, each network interface will ping the ip 192.168.10.1 each 2 seconds.
Then, you have to reconfigure your /etc/network/interfaces file.
The first example uses a DHCP server to get the IP address and so uses the pre-up ifconfig command line.
auto bond0 iface bond0 inet dhcp pre-up modprobe bond0 pre-up ifconfig bond0 up;/sbin/ifenslave bond0 eth0 eth1 hwaddress ether 00:14:5E:D8:xx:xx down ifenslave -d bond0 eth0 eth1
The two pre-up commands ask respectively to add the module/device and its configuration into the kernel and the second allows the DHCP requests to be done before the aggregation is set up.
This can be either one or the other real mac address of you network card or something completely invented. Be aware that you should not found two times the same mac address on your network.
auto bond0 iface bond0 inet static pre-up modprobe bond0 hwaddress ether 00:14:5E:D8:xx:xx address 192.168.10.117 netmask 255.255.255.0 gateway 192.168.10.1 up ifenslave bond0 eth0 eth1 down ifenslave -d bond0 eth0 eth1
on Debian, you can replace the two last lines (up/down) with:
slaves eth0 eth1
You can check the actual configuration of your bonding module by cat-ting the device configuration file:
If you do some modifications on the bonding module configuration file (/etc/modprobe.d/aliases-bond), you need first to remove the bonding module:
modprobe -r bond0
By restarting your network devices either with
it will automatically add again the module because it is asked to do so in the /etc/network/interfaces file with the command “pre-up modprobe bond0”.
This works as for another interface:
ifconfig bond0 down
You can test the failover by detaching (-d) a “dead” interface:
ifenslave -d bond0 eth0
which will warn you as:
bonding: bond0: releasing active interface eth0
and your connection is still active through the eth1 interface.
You can of course reconnect the interface:
ifenslave bond0 eth0