FreeBSD: NIC Bonding / Link Aggregation / Trunking / Link Failover Tutorial

by on February 13, 2009 · 17 comments· LAST UPDATED February 13, 2009

in , ,

I've two Intel gigabit network card installed in HP server. I know how to setup bounding under CentOS Linux, but I'd like to do same under FreeBSD. How do I setup link aggregation of multiple network interfaces as one virtual trunk interface for the purpose of providing fault-tolerance and high-speed links under FreeBSD 7.x server?

FreeBSD has lagg - link aggregation and link failover interface. The lagg interface allows aggregation of multiple network interfaces as one virtual lagg interface for the purpose of providing fault-tolerance and high-speed links.

How do I load lagg driver?

First, you need to load the lagg driver into the memory. To load the driver as a module at boot time, place the following line in loader.conf:
if_lagg_load="YES"
Type the following command to add line to /boot/loader.conf file, enter:
# echo 'if_lagg_load="YES"' >> /boot/loader.conf
To load driver for current session use kldload command, type:
# kldload if_lagg
# kldstat

A note about custom FreeBSD kernels

If you have custom compiled kernel, you need to compile this driver into the kernel, place the following line in your FreeBSD kernel configuration file:
device lagg

How do I create a lagg interface?

A lagg interface can be created using the following command:
# ifconfig laggN create
# ifconfig lagg0 create

It can use different link aggregation protocols specified using the laggproto proto option. The driver currently supports the following aggregation protocols:

Aggregation ProtocolsDescription
failoverSends and receives traffic only through the master port. If the master port becomes unavailable, the next active port is used. The first interface added is the master port; any interfaces added after that are used as failover devices.
fecSupports Cisco EtherChannel. This is a static setup and does not negotiate aggregation with the peer or exchange frames to monitor the link.
lacpSupports the IEEE 802.3ad Link Aggregation Control Protocol (LACP) and the Marker Protocol. LACP will negotiate a set of aggregable links with the peer in to one or more Link Aggregated Groups. Each LAG is composed of ports of the same speed, set to full-duplex operation. The traffic will be balanced across the ports in the LAG with the greatest total speed, in most cases there will only be one LAG which contains all ports. In the event of changes in physical connectivity, Link Aggregation will quickly converge to a new configuration.
loadbalanceBalances outgoing traffic across the active ports based on hashed protocol header information and accepts incoming traffic from any active port. This is a static setup and does not negotiate aggregation with the peer or exchange frames to monitor the link. The hash includes the Ethernet source and destination address, and, if available, the VLAN tag, and the IP source and destination address.
roundrobinDistributes outgoing traffic using a round-robin scheduler through all active ports and accepts incoming traffic from any active port.
noneThis protocol is intended to do nothing: it disables any traffic without disabling the lagg interface itself.

An Example - Create link aggregation using LACP

To create a 802.3ad link aggregation using LACP with two em Intel PRO/1000 Gigabit Ethernet adapter driver Gigabit Ethernet interfaces use the following procedure. First, you do not need to assign any IPs to em0 and em1 interfaces. Do not configure them via /etc/rc.conf. Next, bring up both interfaces, enter:
# ifconfig em0 up
# ifconfig em1 up

Create a lagg interface called lagg0, enter:
# ifconfig lagg0 create
Finally, assign an IP address to lagg0:
# ifconfig lagg0 laggproto lacp laggport em0 laggport em1 10.24.116.2 netmask 255.255.255.192
If you need to create failover between NIC instead of lacp , enter:
# ifconfig lagg0 up laggproto failover laggport em0 laggport em1 10.24.116.2 netmask 255.255.255.192
To verify status of your links, enter:
# ifconfig
You may also need to add a default gateway, enter:
# route add default 10.24.116.100
# netstat -nr

Where,

  • lagg0 : Bounding interface name.
  • laggproto lacp : Bounding protocol. See above tables for possible values.
  • laggport em0 : Your first Ethernet interface name.
  • laggport em1 : Your second Ethernet interface name.
  • 10.24.116.2 : IP address for lagg0 interface.
  • netmask 255.255.255.192 : Netmask address for lagg0 interface.

How do I create an active failover interface?

The following example uses an active failover interface to set up roaming between wired and wireless networks using two network devices. Whenever the wired master interface is unplugged, the wireless failover device will be used:
# ifconfig em0 up
# ifconfig ath0 nwid my_ssid up
# ifconfig lagg0 laggproto failover laggport em0 laggport ath0 192.168.1.1 netmask 255.255.255.0

How do I make link aggregation configuration persistent?

To make link aggregation configuration persistent use cloned_interfaces variable in /etc/rc.conf. Open /etc/rc.conf file, enter:
# vi /etc/rc.conf
Append the following configuration:
ifconfig_em0="up"
ifconfig_em1="up"
cloned_interfaces="lagg0"
ifconfig_lagg0="laggproto failover laggport em0 laggport em1"
ipv4_addrs_lagg0="10.24.116.2/32"
defaultrouter="10.24.116.100"

Save and close the file. Now, FreeBSD will remember your configuration after the system reboot.

References:

The research for this FAQ is based upon the following man pages:

  • rc.conf, ifconfig, and lagg
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 17 comments… read them below or add one }

1 Ashwani February 14, 2009 at 1:01 pm

very good info…but i wonder there are not much of people who r using freeBSD ;-)

Reply

2 Valqk February 16, 2009 at 10:52 am

Oh yes, they are! :)

Reply

3 Ladd Spencer February 18, 2009 at 8:47 pm

Is it possible to use a lagg device to aggregate two ADSL links with static IP addresses? If so, what configuration would be required?

Reply

4 nixCraft February 18, 2009 at 9:42 pm

Yes, you can trunk two ADSL link with lagg. However, I recommend FreeBSD firewall distribution called pfSense. it has exactly what your talking about built in, and easy to configure.

PFSense project

Alternatively, read the ng_one2many(4) and ngctl(8) manual page as a good starting point.

Reply

5 Deskapahendri February 20, 2009 at 4:02 pm

thank you for share and info. i can try at adsl link like speedy :D

Reply

6 Ladd Spencer February 23, 2009 at 4:44 pm

Thanks Vivek, pfSense works great.

Reply

7 RepsaJ April 8, 2009 at 8:51 am
ifconfig_em0="up"
ifconfig_em1="up"
cloned_interfaces="lagg0"
ifconfig_lagg0="laggproto failover laggport em0 laggport em1"
ipv4_addrs_lagg0="192.168.1.1/24"
defaultrouter="192.168.1.254"

Altough PFSense could be handy. Don’t forget some sysadmins would like to have Link Aggregration on their production servers. And then PFSense would require a new server. This trick above you can just use on a production server.

Reply

8 Aleks July 17, 2009 at 7:18 pm

Hi,

Thank you for your tutorial. It really helped me to setup lagg with lacp for my file server.

Reply

9 Julia September 14, 2009 at 10:14 am

Brilliant documentation!
Thanks a lot!

Reply

10 Dave Abrahams December 15, 2009 at 5:37 pm

Hi, this is great to see. Any idea if there’s something similar for MacOS?

Reply

11 RepsaJ December 15, 2009 at 6:45 pm

I have never tried it with a Mac. Altough I found a helpfile on apple.com.

http://docs.info.apple.com/article.html?path=serveradmin/10.4/en/c3ha3.html

http://support.apple.com/kb/TA24277?viewlocale=en_US
On non-server Mac it is supported to.

Reply

12 tex December 21, 2009 at 7:29 pm

Vivek Gite says: “Yes, you can trunk two ADSL link with lagg.”

You cant. Link agregation is layer 3. You dont have layer 3 betwen 2 adsl.

Reply

13 David February 12, 2010 at 1:18 am

For the permanent setup in /etc/rc.conf, I think you want a /24 mask (or whatever prefix length) rather than a /32.

Reply

14 vhor May 31, 2010 at 2:53 pm

Thank you for this tutorial, it helps me.

Reply

15 brij June 4, 2010 at 12:08 pm

Hi, i have two wireless links and want to club the bandwidth of both the links and also provide failover using LAGG.. How can i do it.. and what device L3/L2 switch should i use to do so..

Reply

16 shadow November 2, 2011 at 4:50 pm

this is very good tutorial, it helps me.

Reply

17 Siddharth Rao February 24, 2012 at 9:48 am

Thanks for this. Couple of questions.
1. Do the interfaces have to be up while creating the link aggregation?
2. I suppose we can achieve the same using ioctls, SIOCSLAGG and SIOCGLAGG. I keep getting errors when i try these. Any suggestion in this regard will be very useful.

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous Faq:

Next Faq: