GagA// 0n D nEt

It is currently Sat Dec 15, 2018 8:58 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Howto: Linux NIC bonding
PostPosted: Tue Jul 14, 2009 7:45 pm 
Offline

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
NIC bonding is creation of a single bonded interface by combining 2 or more ethernet interfaces. This helps in high availability and performance improvement.

I'll start with a standard server with 2 NICs, eth0 and eth1. Here is the output from 'ifconfig':

Quote:
[[email protected] ~]# /sbin/ifconfig

Code:
eth0      Link encap:Ethernet  HWaddr 02:06:23:9E:R1:34 
          inet addr:10.0.0.2  Bcast:10.0.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:329563409 errors:0 dropped:0 overruns:0 frame:0
          TX packets:281984862 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:212207668 (202.3 Mb)  TX bytes:2094301826 (1997.2 Mb)
          Base address:0xdcc0 Memory:fcfa0000-fcfc0000

eth1      Link encap:Ethernet  HWaddr 00:04:23:3W:Q1:57
          inet addr:10.0.0.3  Bcast:10.0.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2359168 errors:0 dropped:0 overruns:0 frame:0
          TX packets:923040 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:217316501 (207.2 Mb)  TX bytes:114101861 (108.8 Mb)
          Base address:0xdc80 Memory:fcf80000-fcfa0000

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16379809 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16379809 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3183866656 (3036.3 Mb)  TX bytes:3183866656 (3036.3 Mb)


The configuration scripts are found in /etc/sysconfig/network-scripts/:
Code:
-rw-r--r--    3 root     root          225 Mar 13  2003 ifcfg-eth0
-rw-r--r--    3 root     root          224 Mar 21  2004 ifcfg-eth1
-rw-r--r--    1 root     root          254 Jan 21  2002 ifcfg-lo

First we add a config file for bond0, /etc/sysconfig/network-scripts/ifcfg-bond0. The following will be content of the file:
Code:
DEVICE=bond0
IPADDR=10.0.0.2
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
USERCTL=no
BOOTPROTO=none
ONBOOT=yes

Now we edit /etc/sysconfig/network-scripts/ifcfg-eth0 file and make it look like something below:
Code:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

Now we edit /etc/sysconfig/network-scripts/ifcfg-eth1 file and make it look like something given below:
Code:
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

Network scripts are now complete in /etc/sysconfig/network-scripts:
Code:
-rw-r--r--    3 root     root          133 Jul 13   ifcfg-bond0
-rw-r--r--    3 root     root          225 Jul 13   ifcfg-eth0
-rw-r--r--    3 root     root          225 Jul 13   ifcfg-eth1
-rw-r--r--    1 root     root          254 Jan 21  2002 ifcfg-lo

Set the parameters for bond0 bonding kernel module. Add the following lines to /etc/modprobe. conf
Code:
# bonding commands
alias bond0 bonding
options bond0 mode=balance-alb miimon=100

Load the bond driver module from the command prompt.
Quote:
[[email protected] ~]# modprobe bonding

Restart the network
Quote:
[[email protected] ~]# /etc/init.d/network restart

You should be all set now!

You can now access the box with the IP address assigned to bond0 interface.

Check for the configurations via the following commands:

Quote:
[[email protected] ~]# ifconfig

and
Quote:
[[email protected] ~]# cat /proc/net/bonding/bond0


Top
 Profile  
 
 Post subject: Re: Howto: Linux NIC bonding
PostPosted: Tue Jul 14, 2009 9:16 pm 
Offline

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
You can also use the following quick bonding method:

This small howto will try to cover the most used bonding types. The following script will configure a bond interface (bond0) using two ethernet interface (eth0 and eth1). You can place it onto your on file and run it at boot time:
Code:
#!/bin/bash

modprobe bonding mode=0 miimon=100 # load bonding module

ifconfig eth0 down   # putting down the eth0 interface
ifconfig eth1 down   # putting down the eth1 interface

ifconfig bond0 hw ether 00:11:22:33:44:55   # changing the MAC address of the bond0 interface
ifconfig bond0 192.168.55.55 up   # to set ethX interfaces as slave the bond0 must have an ip.

ifenslave bond0 eth0   # putting the eth0 interface in the slave mod for bond0
ifenslave bond0 eth1   # putting the eth1 interface in the slave mod for bond0

You can set up your bond interface according to your needs. You can refer to the different modes/types of bonding available in the article provided here.

Also you can use multiple bond interface but for that you must load the bonding module as many as you need.
Presuming that you want two bond interface you must configure the /etc/modprobe.conf as follow:
Code:
   alias bond0 bonding
   options bond0 -o bond0 mode=0 miimon=100
   alias bond1 bonding
   options bond1 -o bond1 mode=1 miimon=100

Notes:
Code:
    * To restore your slaves MAC addresses, you need to detach them from the bond (`ifenslave -d bond0 eth0'). The bonding driver will then restore the MAC addresses that the slaves had before they were enslaved.
    * The bond MAC address will be the taken from its first slave device.
    * Promiscous mode: According to your bond type, when you put the bond interface in the promiscous mode it will propogates the setting to the slave devices as follow:
          o for mode=0,2,3 and 4 the promiscuous mode setting is propogated to all slaves.
          o for mode=1,5 and 6 the promiscuous mode setting is propogated only to the active slave.
            For balance-tlb mode the active slave is the slave currently receiving inbound traffic, for balance-alb mode the active slave is the slave used as a "primary." and for the active-backup, balance-tlb and balance-alb modes, when the active slave changes (e.g., due to a link failure), the promiscuous setting will be propogated to the new active slave.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group