Skip to main content

Cấu hình Network (NIC) Bonding/Teaming trên Linux

02,November 2017
Cấu hình NIC bonding teaming trên Linux Server

1. Khái niệm NIC Bonding/Teaming

NIC Bonding/Teaming cho phép bạn cấu hình 2 hay nhiều card mạng chạy failover, loadbalacing và HA với nhau, nếu 1 card bị down thì dịch vụ dẫn chạy bình thường. Tính năng loadbalacing cho phép tăng tốc độ truyển dữ liệu trên card mạng, dữ liệu sẽ được share tải trên các card mạng để tăng tốc độ truyền dữ liệu.

+ Các mode của Bonding

Mode Policy How it works Fault Tolerance Load balancing
0 Round Robin With bond mode 0, would send the first packet out eth0, the second packet out eth1, the third packet our eth2, and then start back at eth0 with the fourth packet. This is where the mode gets its ‘round-robin‘ name No Yes
1 Active Backup
(active-backup)
Only one network interface is active while the other interfaces in the bond simply wait for a failure in the link to the primary network interface card. Yes No
2 XOR [exclusive OR]
(balance-xor) 
In a balance XOR bond mode the bond will evaluate the source and destination mac addresses to determine which interface to send the network packets out. This method will pick the same interface for a given mac address and as a result is capable of load balancing and fault tolerance Yes Yes
3 Broadcast
broadcast
In this method the bond device will transmit data out all slave interfaces hence the ‘broadcast‘ name of this particular bonding method. There are very few uses for this method but it does provide a level of fault tolerance. Yes No
4 Dynamic Link Aggregation
802.3ad
This is a special bond method for link aggregation and does require special configuration on the switch to which this particular bonded interface connects. This method follows the IEEE standards for link aggregation and provides both fault tolerance and increased bandwidth. Yes Yes
5 Transmit Load Balancing (TLB)
balance-tlb
In TLB the bond will receive traffic on the slave interfaces as normal but when the system needs to send traffic, it will determine which interface is the best to transmit data on based upon the load/queue for each of the interfaces. Yes Yes
6 Adaptive Load Balancing (ALB)
balance-alb
In ALB the bond will load balance similar to Bond Mode 5 but with the added ability to load receive balance as well.    

 

2. Cấu hình NIC Bonding/Teaming

a. Trên CentOS 7

- Câu lệnh load bonding modules

# modprobe bonding

- Cấu hình để load module "boding" khi hệ thống khởi động lại 

# vi /etc/modprobe.d/bonding.conf
bonding

- Hiển thị thông tin bonding module 

# modinfo bonding

filename:       /lib/modules/3.10.0-514.el7.x86_64/kernel/drivers/net/bonding/bonding.ko
author:         Thomas Davis, tadavis@lbl.gov and many others
description:    Ethernet Channel Bonding Driver, v3.7.1
version:        3.7.1
license:        GPL
alias:          rtnl-link-bond
rhelversion:    7.3
srcversion:     B664145ACFBCC961505C750

+ Tạo file Bond interface 

# vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
TYPE=Bond
NAME=bond0
BONDING_MASTER=yes
BOOTPROTO=none
ONBOOT=yes
DNS1=8.8.8.8
DNS1=4.4.4.4
IPADDR=192.168.1.70
PREFIX=24
GATEWAY=192.168.1.1
BONDING_OPTS="updelay=0 miimon=100 downdelay=0 fail_over_mac=1 mode=active-backup primary=ens36"  #mode=1

+ Chỉnh lại thông số cho các NIC interfaces (ens33, ens36, ens37) 

# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
MASTER=bond0
SLAVE=yes

# vim /etc/sysconfig/network-scripts/ifcfg-ens36
TYPE=Ethernet
BOOTPROTO=none
NAME=ens36
DEVICE=ens36
ONBOOT=yes
MASTER=bond0
SLAVE=yes

# vim /etc/sysconfig/network-scripts/ifcfg-ens37
TYPE=Ethernet
BOOTPROTO=none
NAME=ens37
DEVICE=ens37
ONBOOT=yes
MASTER=bond0
SLAVE=yes

+ Restart netwrok service

# ip link set dev bond0 down
# ip link set dev bond0 up
# systemctl restart network.service

+ Kiểm tra cấu hình

- Sử dụng "route -n & ifconfig & ip addr" để check bond interface

Cấu hình boding teamming trên CentOS

- Sử dụng câu lệnh sau để hiển thị bond interface settings

# cat /proc/net/bonding/bond0
# dmesg | grep bond0
Cấu hình boding teamming trên CentOS

 

b. Trên Ubuntu 16

- Cấu hình để load module "boding" khi hệ thống khởi động lại 

$ vim /etc/modules

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
lb
rtc
bonding

- Cấu hình  NIC interfaces

$ vim /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet manual
	bond-master bond0
        bond-primary enp0s3

# The second network interface
auto enp0s8
iface enp0s8 inet manual
	bond-master bond0

# The third network interface
auto enp0s9
iface enp0s9 inet manual
	bond-master bond0

# The bond master network interface
auto bond0
iface bond0 inet static
	address 192.168.3.111
	netmask 255.255.255.0
	network 192.168.1.0
	broadcast 192.168.1.255
	gateway 192.168.1.1
        dns-nameservers 8.8.8.8
	bond-milimon 100
	bond-downdelay 200
	bond-updelay 200
        bond-fail-over-mac 1
	bond-mode active-backup
	bond-slaves none

- Khởi động lại networking

# systemctl restart network

+ Kiểm tra cấu hình

- Sử dụng "route -n & ifconfig & ip addr" để check bond interface

- Sử dụng câu lệnh sau để hiển thị bond interface settings

# cat /proc/net/bonding/bond0
# dmesg | grep bond0