Un piccolo riassunto su come effettuare velocemente il bonding delle interfacce di rete su sistemi Debian (Ubuntu 8.04 nella fattispecie) e RH (Centos 5.3).
Come tutti sanno il bonding serve per “unire” in diversi modi piu’ interfacce di rete al fine di migliorare le prestazioni e fornire ridondanza e bla bla bla.
L’unica cosa di cui abbiamo bisogno sono due interfacce di rete (possibilmente identiche) da aggregare. Ovviamente possono essere piu’ di due…
Per Ubuntu:
Su Ubuntu dobbiamo anzitutto installare il pacchetto ifenslave-2.6 che servira’ a dare i comandi di aggregazione/scioglimento delle interfacce. Si puo’ fare tranquillamente con apt-get.
Quindi andiamo a creare il file /etc/modprobe.d/bond che riempiremo in questo modo:
alias bond0 bonding
options bond0 mode=1 miimon=80
La prima riga non fa che associare il nome “bond0” al modulo “bonding“. La seconda riga invece specifica le opzioni per bond0 che sono la modalita’ (vedi sotto per ulteriori dettagli su questo punto) e il parametro miimon che settato ad 80 dice che il polling delle interfacce (per verificare se sono attive regolarmente) viene eseguito ogni 80 millisecondi.
Andiamo quindi a modificare il file /etc/network/interfaces commentando eventuali interfacce presenti (eccetto lo, ovviamente) e inserendo invece:
auto bond0
iface bond0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
network xxx.xxx.xxx.xxx
broadcast xxx.xxx.xxx.xxx
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1
Sostituite con i vostri valori le x e riavviate la macchina. A questo punto dovreste avere le interfacce aggregate in un’unica interfaccia virtuale chiamata bond0. Controllate che tutto sia in ordine con ifconfig e con il comando cat /proc/net/bonding/bond0
Per CentOS
Le cose qui sono leggermente piu’ semplici: non e’ infatti necessario installare alcun pacchetto, basta semplicemente modificare il file /etc/modprobe.conf aggiungendo come prima:
alias bond0 bonding
options bond0 mode=1 miimon=80
E quindi andando a creare il file /etc/sysconfig/network-scripts/ifcfg-bond0 con all’interno:
DEVICE=bond0
IPADDR=xxx.xxx.xxx.xxx
NETMASK=xxx.xxx.xxx.xxx
GATEWAY=xxx.xxx.xxx.xxx
NETWORK=xxx.xxx.xxx.xxx
BROADCAST=xxx.xxx.xxx.xxx
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
Infine dobbiamo modificare i due file delle interfacce esistenti, poniamo /etc/sysconfig/network-scripts/ifcfg-eth0 e eth1 lasciando solo quanto segue:
DEVICE=eth0 (oppure eth1)
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
Infine riavviamo la macchina e testiamo che le due interfacce siano risalite correttamente con i comandi elencati prima.
Modalita’ di bonding:
Queste sono le modalita’ di bonding che possono essere usate, spudoratamente copiate da qui:
mode=0
This mode uses the Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.
mode=1
This mode uses an Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond’s MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.
mode=2
Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.
mode=3
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.
mode=4
IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.
*Pre-requisites:
1. Ethtool support in the base drivers for retrieving the speed and duplex of each slave.
2. A switch that supports IEEE 802.3ad Dynamic link aggregation. Most switches will require some type of configuration to enable 802.3ad mode
mode=5
Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
*Prerequisite: Ethtool support in the base drivers for retrieving the speed of each slave.
mode=6
Adaptive load balancing: includes balance-transmit load balancing plus receive load balancing for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.
