• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 7 : How to create an Network Bonding (NIC teaming) using nmcli

by admin

What is Interface bonding

Bonding (or channel bonding) is a technology-enabled by the Linux kernel and Red Hat Enterprise Linux, that allows administrators to combine two or more network interfaces to form a single, logical “bonded” interface for redundancy or increased throughput. The behavior of the bonded interfaces depends upon the mode; generally speaking, modes provide either hot standby or load balancing services. Additionally, they may provide link-integrity monitoring.

Why use Interface bonding?

The two important reasons to create an interface bonding are :
1. To provide increased bandwidth
2. To provide redundancy in the face of hardware failure

One of the pre-requisites to configure a bonding is to have the network switch which supports EtherChannel (which is true in case of almost all switches).

Bonding modes

Depending on your requirement, you can set the bonding mode to any of the below 7 modes.

Mode Policy How it works Fault Tolerance Load balancing
0 Round Robin packets are sequentially transmitted/received through each interfaces one by one. Yes Yes
1 Active Backup one NIC active while another NIC is asleep. If the active NIC goes down, another NIC becomes active. only supported in x86 environments. Yes No
2 XOR [exclusive OR] In this mode the, the MAC address of the slave NIC is matched up against the incoming request’s MAC and once this connection is established same NIC is used to transmit/receive for the destination MAC. Yes Yes
3 Broadcast All transmissions are sent on all slaves Yes No
4 Dynamic Link Aggregation aggregated NICs act as one NIC which results in a higher throughput, but also provides failover in the case that a NIC fails. Dynamic Link Aggregation requires a switch that supports IEEE 802.3ad. Yes Yes
5 Transmit Load Balancing (TLB) The outgoing traffic is distributed depending on the current load on each slave interface. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed slave. Yes Yes
6 Adaptive Load Balancing (ALB) Unlike Dynamic Link Aggregation, Adaptive Load Balancing does not require any particular switch configuration. Adaptive Load Balancing is only supported in x86 environments. The receiving packets are load balanced through ARP negotiation. Yes Yes

Creating the Network Bonding using nmcli

1. Creating the Bonding interface

1. Use the nmcli connection command without any arguments to view the existing network connections. You can shorten the “connection” argument to “con“. Example:

# nmcli connection 
NAME                UUID                                  TYPE            DEVICE 
ens33               59b61d18-90ed-4c3c-97e0-6c9e0528f25f  802-3-ethernet  ens33  
ens37               c09f18e1-793b-4d60-9107-98762cf593a7  802-3-ethernet  ens37

2. Include the “add type bond” arguments, and any additional information to create a network bond connection. The following example creates a bonded interface named bond0, defines the interface as bond0, sets the mode to “active-backup“, and assigns an IP address to the bonded interface.

# nmcli con add type bond con-name bond0 ifname bond0 mode active-backup ip4 192.168.219.150/24
Connection 'bond0' (1a75eef0-f2c9-417d-81a0-fabab4a1531c) successfully added.

The nmcli con command shows the new bond connection.

# nmcli connection 
NAME                UUID                                  TYPE            DEVICE 
bond0               1a75eef0-f2c9-417d-81a0-fabab4a1531c  bond            bond0  
ens33               59b61d18-90ed-4c3c-97e0-6c9e0528f25f  802-3-ethernet  ens33  
ens37               c09f18e1-793b-4d60-9107-98762cf593a7  802-3-ethernet  ens37

3. The ‘nmcli con add type bond’ command creates an interface configuration file in the /etc/sysconfig/network-scripts directory. For example:

# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BONDING_OPTS=mode=active-backup
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=none
IPADDR=192.168.219.150
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
UUID=1a75eef0-f2c9-417d-81a0-fabab4a1531c
ONBOOT=yes

4. The ip addr command shows the new bond0 interface:

# ip addr show bond0
5: bond0: [BROADCAST,MULTICAST,MASTER,UP] mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.219.150/24 brd 192.168.219.255 scope global bond0
       valid_lft forever preferred_lft forever

2. Creating the Slave Interfaces

1. For each interface that you want to bond, use the ‘nmcli con add type bond-slave‘ command. The following example adds the ens33 interface as a bond slave. The command does not include the con-name argument so a name is automatically generated. You can have the name set for the slave interfaces with the con-name argument.

# nmcli con add type bond-slave ifname ens33 master bond0
Connection 'bond-slave-ens33' (79c40960-6b2c-47ba-a417-988332affed1) successfully added.

2. The following example adds the ens37 interface as a “bond-slave“.

# nmcli con add type bond-slave ifname ens37 master bond0
Connection 'bond-slave-ens37' (46222a52-f2ae-4732-bf06-ef760aea0d7b) successfully added.

3. The nmcli con command shows the new connections.

# nmcli connection 
NAME                UUID                                  TYPE            DEVICE 
bond0               1a75eef0-f2c9-417d-81a0-fabab4a1531c  bond            bond0  
ens33               59b61d18-90ed-4c3c-97e0-6c9e0528f25f  802-3-ethernet  ens33  
ens37               c09f18e1-793b-4d60-9107-98762cf593a7  802-3-ethernet  ens37  
bond-slave-ens33    79c40960-6b2c-47ba-a417-988332affed1  802-3-ethernet  --     
bond-slave-ens37    46222a52-f2ae-4732-bf06-ef760aea0d7b  802-3-ethernet  --   

4. The nmcli con add type bond-slave commands create interface configuration files in the /etc/sysconfig/network-scripts directory. For example:

# cat /etc/sysconfig/network-scripts/ifcfg-bond-slave-ens33
TYPE=Ethernet
NAME=bond-slave-ens33
UUID=79c40960-6b2c-47ba-a417-988332affed1
DEVICE=ens33
ONBOOT=yes
MASTER=bond0
SLAVE=yes
# cat /etc/sysconfig/network-scripts/ifcfg-bond-slave-ens37
TYPE=Ethernet
NAME=bond-slave-ens37
UUID=46222a52-f2ae-4732-bf06-ef760aea0d7b
DEVICE=ens37
ONBOOT=yes
MASTER=bond0
SLAVE=yes

5. The ip addr command includes “SLAVE” for the ens33 and ens37 interfaces and also includes “master bond0“.

3. Activating the Bond

1. You can use the nmcli command to bring up the connections. Bring up the slaves first, and then bring up the bond interface. The following commands bring up the slaves:

# nmcli connection up bond-slave-ens33
# nmcli connection up bond-slave-ens37

2. The following command brings up the bond0 interface:

# nmcli con up bond0

3. The ip addr command, or the ip link command, now shows the slave and the bond interfaces that are UP.

# ip link
2: ens33: [BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:54:f7:20 brd ff:ff:ff:ff:ff:ff
3: ens37: [BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:54:f7:20 brd ff:ff:ff:ff:ff:ff
4: bond0: [BROADCAST,MULTICAST,MASTER,UP,LOWER_UP] mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:54:f7:20 brd ff:ff:ff:ff:ff:ff

Viewing Network Bonding Information

1. Each network interface contains a directory in the /sys/class/net directory. For example:

# ls /sys/class/net
bond0  bonding_masters  ens33  ens36  ens37  lo

2. In this example, a network bond named ‘bond0’ exists. A directory of the same name exists that contains configuration information for that bond. For example:

# ls /sys/class/net/bond0
addr_assign_type  bonding    carrier_changes  dormant  gro_flush_timeout  iflink       lower_ens37   operstate     queues      subsystem     uevent
address           broadcast  dev_id           duplex   ifalias            link_mode    mtu           phys_port_id  speed       tx_queue_len
addr_len          carrier    dev_port         flags    ifindex            lower_ens33  netdev_group  power         statistics  type

3. Within this directory is a bonding directory that contains information for the bond0 interface. For example:

# ls /sys/class/net/bond0/bonding
active_slave       ad_aggregator   ad_select          arp_interval   fail_over_mac  mii_status    num_unsol_na       queue_id        updelay
ad_actor_key       ad_num_ports    ad_user_port_key   arp_ip_target  lacp_rate      min_links     packets_per_slave  resend_igmp     use_carrier
ad_actor_sys_prio  ad_partner_key  all_slaves_active  arp_validate   lp_interval    mode          primary            slaves          xmit_hash_policy
ad_actor_system    ad_partner_mac  arp_all_targets    downdelay      miimon         num_grat_arp  primary_reselect   tlb_dynamic_lb

4. There are also directories that contain information for each of the slaves. For example:

# ls /sys/class/net/bond0/lower_ens33
addr_assign_type  bonding_slave  carrier_changes  dev_port  flags              ifindex    master        operstate     queues      subsystem     uevent
address           broadcast      device           dormant   gro_flush_timeout  iflink     mtu           phys_port_id  speed       tx_queue_len  upper_bond0
addr_len          carrier        dev_id           duplex    ifalias            link_mode  netdev_group  power         statistics  type

5. Following are some examples of viewing files in the /sys/class/net directory.

# cat /sys/class/net/bonding_masters
bond0
# cat /sys/class/net/bond0/operstate
up
# cat /sys/class/net/bond0/address
00:0c:29:54:f7:20
# cat /sys/class/net/bond0/bonding/active_slave
ens33
# cat /sys/class/net/bond0/bonding/mode
active-backup 1
# cat /sys/class/net/bond0/bonding/slaves
ens33 ens37

6. Following is an example of viewing the /proc/net/bonding/bond0 file.

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens33
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: ens33
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:54:f7:20
Slave queue ID: 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:54:f7:34
Slave queue ID: 0

How to disable IPv4 or IPv6 on bonded interface

These steps are only needed if bond1 will not use an ipv4 or ipv6 address

# nmcli connection modify bond1 ipv4.method disabled

and/or

# nmcli connection modify bond1 ipv6.method ignore

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. printk and console log level
  2. fsck Command Examples in Linux
  3. tee Command Examples in Linux
  4. Sample /etc/mke2fs.conf file
  5. nmon Command Examples in Linux
  6. How to configure AD group in sudoers file to provide sudo access to users on Linux system
  7. cpufreq-set Command Examples in Linux
  8. How To Check a Disk for Bad Blocks or Disk Errors on CentOS / RHEL
  9. How to Boot into Rescue Mode or Emergency Mode Through Systemd in CentOS/RHEL 7 and 8
  10. Basic Commands to Troubleshoot Performance Issues in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright