【Linux】网卡的7种bond模式

文章详细介绍了Linux系统中网卡的7种bond模式,包括负载分担、主备模式、XORHash负载分担、广播模式、802.3ad协议支持等,以及每种模式的工作原理和适用场景。此外,还提到了交换机的相应配置需求和服务器上的网卡配置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网卡的7种bond模式

一、bond模式

Mode=0(balance-rr) 表示负载分担round-robin,和交换机的聚合强制不协商的方式配合

Mode=1(active-backup) 表示主备模式,只有一块网卡是active,另外一块是备的standby,这时如果交换机配的是捆绑,将不能正常工作,因为交换机往两块网卡发包,有一半包是丢弃的

Mode=2(balance-xor) 表示XOR Hash负载分担,和交换机的聚合强制不协商方式配合。(需要xmit_hash_policy)

Mode=3(broadcast) 表示所有包从所有interface发出,这个不均衡,只有冗余机制…和交换机的聚合强制不协商方式配合

Mode=4(802.3ad) 表示支持802.3ad协议,和交换机的聚合LACP方式配合(需要xmit_hash_policy)

Mode=5(balance-tlb) 是根据每个slave的负载情况选择slave进行发送,接收时使用当前轮到的slave

Mode=6(balance-alb) 在5的tlb基础上增加了rlb

模式策略特点负载均衡交换机配置
bond0(balance-rr)Round-robin policy 平衡轮询策略依次传输(即:第一次包走eth0,下一个包走eth1…一直循环下去,直到最后一个传输完毕)静态聚合
bond1(active-backup)Active-backup policy 主-备份策略只有一个端口处于活动状态,当一个宕掉后另一个马上状态由备变为主,mac地址唯一
bond2(Banlance-xor)XOR policy 平衡策略基于指定的HASH策略传输数据包静态聚合
bond3(broadcast)broadcast 广播策略每个slave接口上传输每个数据包静态聚合
bond4(802.3ad)IEEE 802.3ad Dynamic link aggregation (IEEE 802.3ad 动态链接聚合)创建一个聚合组,他们共享相同的速率和双工设定,根据802.3ad规范将多个slave工作在同一个激活的聚合体下支持IEEE 802.3ad动态聚合
bond5(balance-tlb)Adaptive transmit load balancing 适配器传输负载均衡根据每个slave的负责情况选择salve进行发送,接收时使用当前轮到的slave
bond6(balance-alb)Adaptive load balancing 适配器适应性负载均衡先把eth0流量占满,再占eth1…ethX。该模式包含了balance-tlb模式,同时加上针对IPV4流量的接受负载均衡(reveive load balance rlb)

二、交换机设置

mode 1、5、6不需要交换机设置
  mode 0、2、3需要交换机设置静态聚合,mode 4需要交换机支持802.3ad

三、网卡配置文件

2个物理网口分别是:eth0,eth1

绑定后的虚拟口是:bond0

服务器IP是:192.168.0.100

1)修改eth0配置文件

vim /etc/sysconfig/network-scripts/ifcfg-eth0
  DEVICE=eth0
  BOOTPROTO=none
  MASTER=bond0
  SLAVE=yes
  ONBOOT=yes

2)修改eth1配置文件

vim /etc/sysconfig/network-scripts/ifcfg-eth1
  DEVICE=eth1
  BOOTPROTO=none
  MASTER=bond0
  SLAVE=yes
  ONBOOT=yes

3)修改bond0配置文件

vim /etc/sysconfig/network-scripts/ifcfg-bond0
  DEVICE=bond0
  BOOTPROTO=static
  IPADDR=192.168.0.100
  NETMASK=255.255.255.0
  ONBOOT=yes

4)修改bonding配置文件

CentOS6追加写/etc/modprobe.d/dist.conf,CentOS7新建写/etc/modprobe.d/bonding.conf

alias bond0 bonding
options bond0 miimon=100 mode=6

5)加载bonding模块

modprobe bonding

确认模块是否加载成功

lsmod |grep bonding

6)重启网络

service network restart

查看bond

cat /proc/net/bonding/bond0

四、设置多个bond

1)多个bond口的模式设成相同

alias bond0 bonding
alias bond1 bonding
options bonding max_bonds=2 miimon=100 mode=6

2)不同的bond口mode设成不一样

alias bond0 bonding
options bond0 miimon=100 mode=1
install bond1 /sbin/modprobe bonding -o bond1 miimon=100 mode=0 

miimon:监视网络链接的频度,单位是毫秒,我们设置的是100毫秒

max_bonds:配置的bond口个数

mode:bond模式,在一般的实际应用中,0和1用的比较多

官方介绍:

  • mode=0 (Balance Round Robin) per packet
  • mode=1 (Active backup)
  • mode=2 (Balance XOR)
  • mode=3 (Broadcast)
  • mode=4 (802.3ad)
  • mode=5 (Balance TLB)
  • mode=6 (Balance ALB)

Modes of bonding :

RHEL bonding supports 7 possible “modes” for bonded interfaces. These modes determine the way in which traffic sent out of the bonded interface is actually dispersed over the real interfaces. Modes 0, 1, and 2 are by far the most commonly used among them.

    • Mode 0 (balance-rr)
      This mode transmits packets in a sequential order from the first available slave through the last. If two real interfaces are slaves in the bond and two packets arrive destined out of the bonded interface the first will be transmitted on the first slave and the second frame will be transmitted on the second slave. The third packet will be sent on the first and so on. This provides load balancing and fault tolerance.
    • Mode 1 (active-backup)
      Mode 1 places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. Only one slave in the bond is active at an instance of time. A different slave becomes active only when the active slave fails. This mode provides fault tolerance.
    • Mode 2 (balance-xor)
      Transmits based on XOR formula. (Source MAC address is XOR’d with destination MAC address) modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance.
    • Mode 3 (broadcast)
      The broadcast mode transmits everything on all slave interfaces. This mode is least used (only for a specific purpose) and provides only fault tolerance.
    • Mode 4 (802.3ad)
      The 802.3ad mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link. Slave selection for outgoing traffic is done according to the transmit hash policy, which may be changed from the default simple XOR policy via the xmit_hash_policy option. Note that not all transmit policies may be 802.3ad compliant, particularly in regards to the packet mis-ordering requirements of section 43.2.4 of the 802.3ad standard. Differing peer implementations will have varying tolerances for noncompliance.
    • Mode 5 (balance-tlb)
      This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave.
    • Mode 6 (balance-alb)
      This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses for the server.

参考链接

https://www.cnblogs.com/lcword/p/5914089.html
https://www.cloudibee.com/network-bonding-modes/

### 如何检查网卡 Bond 模式 4 的状态 为了确认 Linux 系统中的网卡是否成功配置为 Bonding 模式 4 (802.3ad),以及其当前的工作状况,可以采用多种方法来获取这些信息。 #### 使用 `cat` 命令读取 `/proc/net/bonding/` 文件夹下的文件 每一块绑定接口的信息都会被记录在这个路径下对应的文件里。对于名为 `bond0` 的设备来说: ```bash cat /proc/net/bonding/bond0 ``` 该命令将会输出有关此 bond 接口的所有设置详情,包括所使用的模式、活动端口列表以及其他重要参数[^1]。 #### 利用 `ifconfig` 或者更现代的 `ip link show` 来查看基本属性 通过执行下面任何一个命令可以获得关于网络接口的基础数据,比如 MTU 大小、MAC 地址等基本信息,并且能够看到是否有错误包的存在。 ```bash ifconfig bond0 # 或者使用 iproute2 工具集里的命令代替老旧版本 ip link show dev bond0 ``` 如果一切正常的话,在这里应该能看到类似于 "state UP" 这样的字样表示接口处于激活状态;同时也能观察到 slave 设备的数量及其名称[^2]。 #### 验证 LACP 协议交互情况 由于 Mode 4 特指 IEEE 802.3ad 动态链接聚合标准,因此还需要进一步验证 Link Aggregation Control Protocol (LACP) 是否正在运行并交换 PDU 数据报文。这可以通过阅读上述提到过的 procfs 中的内容实现: ```bash grep lacp_rate /sys/class/net/bond0/bonding/* ``` 当返回的结果中含有 fast 字样,则意味着 LACP 正常工作于快速协商周期内(即每隔 1 秒发送一次)[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值