1. 准备工作
安装包
sudo apt-get install ifenslave
确保对应的模块已经加载。编辑/etc/modules
文件,加入bongding:
sudo 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.
loop
lp
rtc
bonding
2. 配置网络
先确保网络已经下线:
sudo stop networking
然后加载bonding模块:
sudo modprobe bonding
编辑/etc/network/interfaces
文件配置网络。以下的例子将eth0设置为主网卡,可以根据自己的需要调整。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#auto eth0
#iface eth0 inet dhcp
# This is an autoconfigured IPv6 interface
#iface eth0 inet6 auto
# eth0 is manually configured, and slave to the "bond0" bonded NIC
auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0
# eth1 ditto, thus creating a 2-link bond.
auto eth1
iface eth1 inet manual
bond-master bond0
# bond0 is the bonding NIC and can be used like any other normal NIC.
# bond0 is configured using static network information.
auto bond0
iface bond0 inet dhcp
# address 192.168.1.10
# gateway 192.168.1.1
# netmask 255.255.255.0
bond-mode active-backup
bond-miimon 100
bond-slaves none
非DHCP的需要手动把address/gateway/dns-nameservers之类的都配好
重启网络:
/etc/init.d/networking start
上面这一条现在已经无效了,可以先卸载网卡然后重新up上去。即
sudo ifdown xxx && sudo ifup xxx
,或者直接重启系统。
加载bond0网卡:
sudo ifup bond0
链接的信息可以在/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: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:16:3e:1f:08:6d
Slave queue ID: 0
3. 参考链接
[1] https://help.ubuntu.com/community/UbuntuBonding
[2] https://blog.csdn.net/yzy1103203312/article/details/78646753