Oamc

网卡绑定(bonding) · 修改记录

这是 linux/bonding.md 的每次改动内容,按时间从新到旧。其他文章一起提交的部分不会出现在这里。

#1 2026-10-18 +69 −0 docs: 网络进阶(MSTP/ACL/NAT/PBR)、Linux 进阶(模块/性能/bonding)、Windows 进阶(DFS/DHCP/AD CS) 42afade
 new file mode 100644
 @@ -0,0 +1,69 @@
+---
+tags: [bonding, 网卡绑定, 高可用]
+order: 110
+---
+
+# 网卡绑定(bonding)
+
+## 场景
+
+服务器两块网卡要做冗余(主备)或带宽叠加(LACP)。
+
+## 前置条件
+
+- 两块网卡都没有在用
+- 交换机侧配合(LACP 需要交换机配聚合)
+- 有控制台兜底,改网络容易失联
+
+## 配置
+
+NetworkManager 方式(推荐):
+
+```bash
+nmcli con add type bond con-name bond0 ifname bond0 \
+  bond.options "mode=active-backup,miimon=100"
+
+nmcli con add type ethernet con-name bond0-slave1 ifname ens33 master bond0
+nmcli con add type ethernet con-name bond0-slave2 ifname ens34 master bond0
+
+nmcli con mod bond0 ipv4.addresses 10.0.0.5/24
+nmcli con mod bond0 ipv4.gateway 10.0.0.1
+nmcli con mod bond0 ipv4.dns 10.0.0.2
+nmcli con mod bond0 ipv4.method manual
+nmcli con up bond0
+```
+
+常见模式:
+
+| 模式 | 说明 |
+| --- | --- |
+| `active-backup`(1) | 主备,交换机不用配 |
+| `802.3ad`(4) | LACP,需要交换机配置聚合组 |
+| `balance-xor`(2) | 按哈希分流,交换机要配静态聚合 |
+| `broadcast`(3) | 双发,浪费带宽,特殊场景用 |
+
+## 验证
+
+```bash
+cat /proc/net/bonding/bond0
+nmcli con show
+ip a show bond0
+```
+
+`MII Status` 和 `Slave Interface` 都要 up。
+
+## 回滚
+
+```bash
+nmcli con delete bond0
+nmcli con up ens33
+```
+
+## 坑
+
+- **`802.3ad` 交换机没配 LACP**,链路根本起不来。
+- 主备模式切主时会有短暂丢包,`miimon` 别设太大。
+- bond0 的 IP 配错或网关写错,直接失联。
+- 两块网卡速率不同,LACP 只按最小的算。
+- 改 bond 配置要重启网络,先确认能进控制台。
+- 虚拟机上做 bonding 意义不大,宿主机层面已经冗余了。