Article Information
- Category: Linux
- Date: 14 November, 2020
Linux - Setup Network Bonding with Netplan
If you have a Network Interface Cars (NIC) with multiple ports, it may be a good idea to set up network bonding. Network bonding is a way to combine multiple physical ethernet ports programmatically so that they act as one.-
Why bother with bonding?
Theres quite a few specific reasons to enable network bonding but esentially they all boil down to two reasons; throughput and fault tolerence. A few of the modes either send the same data on different interfaces or they use backup interfaces they switch to in case of failure which provides fault tolerence. Others bind multiple interfaces as one to increase throughput. If you have 2 one Gbps ethernet cables combined then, theoretically, you can have up to 2 Gbps throughput. -
What are some good use cases?
For the majority of people that will read this, the typical use case is going to be a LAN configuration. Currently, I have two servers in my rack, a typical virtualization server and a Network Attached Storage server (NAS). Each one has 2 network bonds setup one network bond connects to eachother directly since my NAS holds alot of my media data that the server needs. The other bond for each connects to a switch which is connected to the network. -
Choosing a bonding mode
There are a total of 7 bond modes supported by netplan. Below, each mode is listed with a short description. At the bottom of the page is an example configuration using the balanace-alb mode.-
balance-rr
Round-robin policy: Transmit packets in order from the first available interface to the last. This mode provides load balancing and fault tolerance. -
active-backup
Active-backup policy: Only one interface in the bond is active. A different interface becomes active if, and only if, the active interface 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. -
balance-xor
XOR policy: Transmit based on selectable hashing algorithm. The default policy is a simple source+destination MAC address algorithm. Alternate transmit policies may be selected via the xmit_hash_policy option, described below. This mode provides load balancing and fault tolerance. -
broadcast
Broadcast policy: transmits everything on all interfaces. This mode provides fault tolerance. -
802.3ad
IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all interfaces in the active aggregator according to the 802.3ad specification.
Requires: Ethtool support and a network switch that supports 802.3ad mode -
balance-tlb
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 interface. Incoming traffic is received by the current interface. If the receiving interface fails, another interface takes over the MAC address of the failed receiving interface.
Requires: Ethtool support -
balance-alb
Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) 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 interfaces in the bond such that different peers use different hardware addresses for the server.
-
balance-rr
The Configuration below is an example configuration I use for my server to set up balance-alb bond monde, it includes some comments with a brief explanation, but if you need or want more information theres always netplan documentation.
/etc/netplan/*.yml
network:
version: 2
#Ethernet interface names, YOURS MAY BE NAMED DIFFERENTLY
ethernets:
eno1:
#Disables DHCP for the interface.
dhcp4: no
#Optional option allows for this interface to be disabled without breaking the bond.
optional: true
eno2:
dhcp4: no
optional: true
eno3:
dhcp4: no
optional: true
eno4:
dhcp4: no
optional: true
#You can try to use regex matching like below, but I had some issues with it.
#eports:
#match:
#name: eno*
#optional: true
bonds:
bond0:
#set all the interfaces for the bond.
interfaces: [eno1, eno2, eno3, eno4]
#If you dont want a static IP, remove the `addresses` line and uncomment the dhcp4 line below
#dhcp4: yes
#Define the bond static IP and gateway
addresses: [192.168.0.21/24]
gateway4: 192.168.0.1
#Typical DNS servers
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
#Set the Bond parameters
parameters:
mode: balance-alb
#lacp-rate: fast
#mii-monitor-interval: 1