Author Topic: Interface bonding How and Why  (Read 2555 times)

oshunluvr

  • Guest
Interface bonding How and Why
« on: October 08, 2009, 12:52:27 AM »
Topic came up in another thread so here's what's up...

I use interface bonding - joining two or more ethernet connections - to act as one. This can have to effect of doubling your connection speed and adding redundancy. Here is the thread that started it http://www.pclinuxos.com/forum/index.php?topic=62875.15.

In my case the "Why" is because I had double ethernet ports on several of the computers on my home network. The parts of the network of interest to this topic are: 2 desktop power machines, 1 media machine, and 1 server. All these motherboards have dual ports and were connected via a single unmanaged switch. I had an opportunity to upgrade my switch to a 16 port unit for $65 so I did that and therefore had the ports available to do this.

Notes of interest: The bonded connections must be via the SAME switch/router to have any speed benefit unless you have fancy switches that allow you to join them together to act as one (I don't). Switched with multiple connections don't automatically "bond." The brand and type of switch is of little difference for bonding purposes.

"How"
Only one of my computers runs PCLinuxOS (the server) and tend to do my configuring manually. Some distros (openSUSE for one) have a GUI that can configure bonded interfaces. Last time I checked pclos did not.

These files are found in /etc/sysconfig/network-scripts
Here's my ifcfg-eth0 file:
Code: [Select]
DEVICE=eth0
ONBOOT=no
USERCTL=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
MII_NOT_SUPPORTED=yes
MTU=4088
ifcfg-eth1 looks exactly the same EXCEPT for - you guessed it - the DEVICE line says eth1 (go figure  ::)  )

ifcfg-bond0
Code: [Select]
DEVICE=bond0
IPADDR=192.168.1.250
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MII_NOT_SUPPORTED=yes
GATEWAY=192.168.1.1
MS_DNS1=192.168.1.1
RESOLV_MODS=yes
IPV6INIT=no
IPV6TO4INIT=no
MTU=4088
You can see I use a static IP, but you can use DHCP without issues. Also, DNS and gateway are pointed at my external router. Use your settings as required. The MTU settings are particular to my ethernet ports and you should use the correct setting for yours.

Next, edit the file /etc/modprobe.conf and add
Code: [Select]
alias bond0 bonding
options bond0 max_bonds=2 miimon=100 mode=0
mode=0 sets us at "round-robin" or load balancing. This allows packets to be sent alternating over all bonded ports creating load sharing (speed increase) and fault tolerance (a failed port won't bring the interface down).

Finally, edit and put the word "bonding" in your /etc/modprobe.preload file. Also type "modprobe bonding" in a console so you can launch your new bonded port without rebooting.

At this point, "service network restart" (as root user or with "sudo") should bring up your new "bond0" port. Notice both ethernet ports and your bond port will show the same MAC adress - this is normal. The bonded interface automatically assumes the MAC address from the first ethernet port bonded and then assigns the same address to all other ports.

Offline blackhole

  • Full Member
  • ***
  • Posts: 66
Re: Interface bonding How and Why
« Reply #1 on: October 08, 2009, 09:16:20 AM »
Hi oshunluvr !

I'm not a network admin so I'm a little bit puzzled with this, but .... yipeeee your how to works on mine.

Code: [Select]
[root@localhost user]# /etc/init.d/network restart
Shutting down interface eth0:                                   [  OK  ]
Shutting down loopback interface:                               [  OK  ]
Bringing up loopback interface:                                 [  OK  ]
Bringing up interface bond0:                                    [  OK  ]
[root@localhost user]# ifconfig
bond0     Link encap:Ethernet  HWaddr 08:00:27:8D:3E:4C
          inet addr:10.10.13.61  Bcast:10.10.13.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:4088  Metric:1
          RX packets:114 errors:0 dropped:0 overruns:0 frame:0
          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:24810 (24.2 KiB)  TX bytes:10680 (10.4 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:8D:3E:4C
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:4088  Metric:1
          RX packets:114 errors:0 dropped:0 overruns:0 frame:0
          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:24810 (24.2 KiB)  TX bytes:10680 (10.4 KiB)

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:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:940 (940.0 b)  TX bytes:940 (940.0 b)

[root@localhost user]#

Thank you very much for sharing.  ;)

One question more if you don't mind,
how can i test this bonding speed ?
and thank you very very much in advance.  :-*
« Last Edit: October 08, 2009, 09:32:14 AM by blackhole »

oshunluvr

  • Guest
Re: Interface bonding How and Why
« Reply #2 on: October 08, 2009, 04:51:26 PM »
I don't believe it's in the repo so maybe you can make a request for it - Iperf does a simple and great job.

I think you can use ethtool to test it, but Iperf sends packets and reports speed. You might get some meaningful results from pinging also.

Your post shows only one port attached to your bonded port show you won't see any speed increase unless you add at least one more port.

Offline blackhole

  • Full Member
  • ***
  • Posts: 66
Re: Interface bonding How and Why
« Reply #3 on: October 08, 2009, 10:39:48 PM »
Quote
Your post shows only one port attached to your bonded port show you won't see any speed increase unless you add at least one more port.
uh oh ... ok thanks, I will take a look at it. This should be for eth1.

Quote
I don't believe it's in the repo so maybe you can make a request for it - Iperf does a simple and great job.

I think you can use ethtool to test it, but Iperf sends packets and reports speed. You might get some meaningful results from pinging also.
Ok. thank you very much for your suggestion. 
If it's not must be too technical, maybe I can just use copying huge file and pay attention on the transfer speed and comparing between bonding or not.

Glad to learn a new thing   ;D

Offline yodelu

  • PCLinuxOS Tester
  • Sr. Member
  • *******
  • Posts: 317
Re: Interface bonding How and Why
« Reply #4 on: October 09, 2009, 03:44:07 AM »
+1

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Interface bonding How and Why
« Reply #5 on: October 09, 2009, 05:16:20 AM »
Maybe I am misunderstanding something here, but I am failing to see how this could improve performance for a Desktop PC connected to the internet through a router and modem -- cable or ADSL.

A single NIC is likely to be a 10/100 if on older equipment and 1G if on newer PCs.
I have no hope of getting anywhere close to any of those figures with my ISP connection speed.
OK, I accept that some people possibly can.

Now if the intention is to use the two or more NICs in a server box, bonded to give a better max out of the server, I think I can see the gains that are available. More PCs could get better speeds from the server with bonding than without ..... if I am understanding what is being done.

On the other hand I can see a reliability gain for a Desktop PC using both NICs ...... whether bonded or not. The switching from one NIC to another with bonding should be seemless I guess so no delays as would likely be the case if the NICs are not bonded.

Lastly a question ........ can an ethernet NIC be bonded with a wireless NIC?

.... interesting subject ......  ;)

oshunluvr

  • Guest
Re: Interface bonding How and Why
« Reply #6 on: October 10, 2009, 04:05:02 PM »
Quote
Maybe I am misunderstanding something here, but I am failing to see how this could improve performance for a Desktop PC connected to the internet through a router and modem -- cable or ADSL.
It doesn't - note that I have 6 computers on my network at home and I stream video through several of them. It improves NETWORK performance not INTERNET performance - Apples and Oranges OK - more like Green Apples and Red ones  :D

Quote
A single NIC is likely to be a 10/100 if on older equipment and 1G if on newer PCs.
I have no hope of getting anywhere close to any of those figures with my ISP connection speed.
OK, I accept that some people possibly can.
Agreed, but see the above comment

Quote
Now if the intention is to use the two or more NICs in a server box, bonded to give a better max out of the server, I think I can see the gains that are available. More PCs could get better speeds from the server with bonding than without ..... if I am understanding what is being done.
Bingo! But also better access to that server from any connected desktop. Faster throughput means more access time and bandwidth for the slower units attached also - in a very general sort of way.

Quote
On the other hand I can see a reliability gain for a Desktop PC using both NICs ...... whether bonded or not. The switching from one NIC to another with bonding should be seemless I guess so no delays as would likely be the case if the NICs are not bonded.
Totally true - you can actually unplug a cable during transmission with no noticeable effect on your system.
Quote
Lastly a question ........ can an ethernet NIC be bonded with a wireless NIC?
I haven't tried this yet but I don't see why not. If it works, you could move your laptop from one hardwired location to another without losing your connection (assuming you've bonded with the wireless) cool idea!

Also note that my network has 12 devices (tivos, sat boxes, and more) PLUS wireless guests, some of which are dhcp enabled and others not. I like to use fixed IP's for my 'puters so I can see who's doing what and more easily trouble shoot. Bonding allows all the connections on a particular box to share the same IP to reduce conflicts and ease identification. If you're into lan parties and have dual ports - you no longer have to worry which port is the right one to connect to your host!

I have also discovered if I'm using an unmanaged switch and I connect two NIC's and they're both up (with different IP's) that will block network access. I'm not sure why, but it always does.

Since many (most?) new mobos have dual ethernet ports, why not take advantage of them where we can?
« Last Edit: October 10, 2009, 04:07:02 PM by oshunluvr »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Interface bonding How and Why
« Reply #7 on: October 10, 2009, 06:16:58 PM »
oshunluvr,
                  thanks for the reply.
Don't forget to let us know what happens when you try this with one wireless NIC ..... enquiring minds want to know   ;D

oshunluvr

  • Guest
Re: Interface bonding How and Why
« Reply #8 on: October 12, 2009, 02:54:13 PM »
I'm getting a new netbook in a few weeks,. I'll try it one that one and report...

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Interface bonding How and Why
« Reply #9 on: October 12, 2009, 03:55:59 PM »
I'm getting a new netbook in a few weeks,. I'll try it one that one and report...

Great ... look forward to hearing about it!   ;)

Offline RadOH

  • Hero Member
  • *****
  • Posts: 717
Re: Interface bonding How and Why
« Reply #10 on: April 19, 2010, 06:57:33 PM »
 ;D
45 days old...we been busy.......ok  ;)
(from pclos 2007)
Here is the how to that I've kept from the GREAT user who posted it, since I don't know ?
How to or even too update this for PCLOS 2010 kde. Or if needed...

Most modern motherboards have two (mabye more?) ethernet ports. ( or usb ports ) If you access the internet
or other devices via a home network - for the price of a cable you can add some functionality
to your connection.

AS WITH ALL EXPERIMENTS: Backup the files used in this tip - no point in needless headaches
if this doesn't work for you!

This short HOWTO will tell you how to 'bond' two (or more) physical ethernet interfaces
together to look and act as a single interface under Linux. It was originally written for
Mandrake Linux users but it has also been tested on recent versions of Mandriva Linux and
I adapted it to our PCLinuxOS. ( But not for PCLOS 2010 kde )

In /etc/modprobe.conf, you should have something similar to the following:
   alias eth0 sky2
   alias eth1 sky2

Add these lines as well:
   alias bond0 bonding
   alias bond1 bonding
   options bond0 max_bonds=2 miimon=100 mode=0
   options bond1 miimon=100 mode=0
(more on "mode" below)

In /etc/sysconfig/network-scripts/ you should have these two files:
   ifcfg-eth0
   ifcfg-eth1

In /etc/modprobe.preload add this line:
        bonding

Edit them so they look like this:
   DEVICE=eth0   # or eth1 for ifcfg-eth1
   USERCTL=no
   ONBOOT=yes
   MASTER=bond0
   SLAVE=yes
   BOOTPROTO=none
   MII_NOT_SUPPORTED=yes

The bond0 file contains the actual IP address information,
so create a new file here called ifcfg-bond0 that contains:
   DEVICE=bond0
   IPADDR=192.168.1.1
   NETMASK=255.255.255.0
   ONBOOT=yes
   BOOTPROTO=none
   USERCTL=no
   MII_NOT_SUPPORTED=yes
Use the correct information for your network connection. IMO the easiest way
to create this file correctly is to copy your original ifcfg-eth0
(or eth1 if you connect through that interface) and name it ifcfg-bond0 then do the edits above.

To use your new bonded interface right now - enter "modprobe bonding" and
"service network restart" in a console as root. This should present you with a new 'bond0'
interface. This is the interface you should see traffic going in and out of if you were to
tcp dump the interface.

You will also notice typing "ifconfig" that all of the ethX interfaces are up,
but only bond0 has an IP address and they all have the same MAC address.
Bonding automatically assigns the primary ethernet port MAC adress to all interfaces.

This example assumes you have two interfaces and want to use them in a 'round-robin' setup.
Here are the available modes:

    Mode 0: Round Robin.  Transmissions are load balanced by sending from available interfaces
sequentially packet by packet.  Transmissions only are load balanced.  
Provides load balancing and fault tolerance.

    Mode 1: Active-Backup. This is the simplest mode of operation for bonding.
Only one Ethernet slave is active at any one time. When the active connection fails
another slave is chosen to take over as the active slave and the MAC address is transferred
to that connection. The switch will effectively view this the same as if the host was disconnected
from one port and then connected to another port. This mode provides fault tolerance but does not
provide any increase in performance.

    Mode 2: Balanced XOR. This is a simple form of load balancing using the XOR of the MAC
addresses of the host and the destination. It works in general fairly well but always sends
the packets through the same channel when sending to the same destination. This means that it
is relatively effective when communicating with a large number of different remote hosts but
loses effectiveness as the number decreases becoming worthless as the value becomes one.
This mode provides fault tolerance and some load balancing.

    Mode 3: Broadcast. This mode simply uses all channels to mirror all transmissions.
It does not provide any load balancing but is for fault tolerance only.

    Mode 4: IEEE 803.ad Dynamic Link Aggregation. This mode provides fault tolerance as well
as load balancing. It is highly effective but requires configuration changes on the switch and
the switch must support 802.3ad Link Aggregation.

    Mode 5: Adaptive Transmit Load Balancing. This mode provides fault tolerance and transmit
(out going) load balancing. It provides no receiving load balancing.  This mode does not
require any configuration on the switch.  Ethtool support is required in the network adapter
(NIC) driver.

    Mode 6: Adaptive Load Balancing.  Like mode five but provides fault tolerance and
bidirectional load balancing.  The transmit load balancing is identical but receipt load
balancing is accomplished by ARP trickery.
« Last Edit: April 19, 2010, 08:57:11 PM by RadOH »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Interface bonding How and Why
« Reply #11 on: April 20, 2010, 02:49:26 AM »
RadOH,
               thanks for the update and concise how-to.
I have given this very little thought in the meantime, but it is something that continues to interest me.

Have you been able to determine if you have a two fold increase in transfer speed between PCs?

What is the most limiting factor on the LAN which is limiting transfer speed?

Just about all devices I have at home are 100Mb/s devices, with the exception of NICs in a couple of PCs, which are 1GB/s.

What would it take to max out the router's switch or even another switch introduced ? .......  both being 100Mb/s devices.

Thanks again for the write-up.   ;)

regards.

Offline RadOH

  • Hero Member
  • *****
  • Posts: 717
Re: Interface bonding How and Why
« Reply #12 on: April 22, 2010, 06:20:55 PM »
 ;D ????

All good questions, I'll research for answers, but posted  from another PCLOS user,
this did work for 2007 and was hoping to get updated for 2010.  ;D