How do I setup a bonding device bond0 and enslave two real Ethernet (say eth0 and eth2) devices to it on Ubuntu Linux 140.04 or 16.04 LTS server? How can I create 802.3ad bonding mode (IEEE 802.3ad Dynamic link aggregation) on Ubuntu Linux 16.04 LTS server?

You need to install and use a tool called ifenslave. It will attach and detach slave network devices to a bonding device. The Linux kernel comes with bonding driver which provides a method for aggregating multiple network interfaces into a single logical “bonded” interface. You need bonding to get higher data rates and as well as link failover.

Install ifenslave on Ubuntu

Type the following command:
$ sudo apt install ifenslave

Our sample setup

  • Bonding interface name: bond0
  • Link aggregation type: 802.3ad (mode 4)
  • Physical interfaces: eth0 and eth2 (as per your needs)
  • IP address assigned only to: bond0 (do not assign any IP address to eth0 and eth2 interfaces)

How to setup a bonding device on Ubuntu Linux

The following example shows how to setup a bonding device and enslave two real Ethernet devices to it from command prompt:

  1. Load driver, run: # modprobe bonding
  2. Setup bond0 with an IP address, run: # ifconfig bond0 192.168.1.254 netmask 255.255.255.0
  3. Enslave two interfaces, run: # ifenslave bond0 eth0 eth2
  4. Verify it: # ifconfig bond0
  5. View bonding info: # more /proc/net/bonding/bond0

Persistent bond0 configuration

Edit /etc/network/interfaces file, run:
$ sudo vi /etc/network/interfaces
Edit/update your config file as follows:

auto bond0
iface bond0 inet static
# Example add eth0 speed if needed (I'm going with auto detect/nego)
#pre-up /usr/sbin/ethtool -s bond0 speed 1000 duplex full autoneg on
post-up ifenslave bond0 eth0 eth2
pre-down ifenslave -d bond0 eth0 eth2
bond-slaves none
# 802.3ad mode
bond-mode 4
bond-lacp-rate fast
bond-miimon 100
bond-downdelay 0
bond-updelay 0
bond-xmit_hash_policy 1
address 192.168.1.254
netmask 255.255.255.192
# Add static route example if you needed #
# up route add -net xx.tt.yy.zz/X gateway a.b.c.d
# down route del -net xx.tt.yy.zz/X
 
auto eth0
iface eth0 inet manual
# Example add eth0 speed if needed
#pre-up /usr/sbin/ethtool -s eth0 speed 1000 duplex full autoneg on
 
auto eth2
iface eth2 inet manual
# Example add eth2 speed if needed
#pre-up /usr/sbin/ethtool -s eth2 speed 1000 duplex full autoneg on

Save and close the file. Restart the the networking service on Ubuntu Linux 14.04 LTS or older:
$ sudo /etc/init.d/networking restart
For Ubuntu Linux 16.04 LTS, enter:
$ sudo systemctl restart networking

Verify new settings

$ ip a show bond0
OR
$ ifconfig bond0
Sample outputs:

6: bond0:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:25:90:4f:b0:6c brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.254/26 brd 10.86.115.127 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::225:90ff:fe4f:b06c/64 scope link 
       valid_lft forever preferred_lft forever

To see the current status of Linux kernel bonding driver and bond0 interface type:
$ more /proc/net/bonding/bond0
Sample outputs:

Fig.01: bond0 status

See also:


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Aaron Jul 12, 2016 @ 18:13

    Here’s a script for that :)

    https://github.com/sivel/bonding

  • Rasitha Jul 13, 2016 @ 2:26

    Dous this need a mode4 compatible network switch to it to actually work?

  • Klez Jul 13, 2016 @ 17:19

    screen-shot of yours is showing incorrectly configured bonding (probably on switch side):
    “Number of ports: 1”, partner/actor Churned status etc.

    furthermore you don’t need to do:
    post-up ifenslave bond0 eth0 eth2
    pre-down ifenslave -d bond0 eth0 eth2

    as per: https://help.ubuntu.com/community/UbuntuBonding

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum