PVE 配置 bonding 聚合网卡

我的需求是聚合有线网卡和 Wi-Fi 无线网卡。问了 AI ,AI 说不行。

我之前在 armbian 上用 netplan 进行过配置和尝试,结果是可行的。

以我的机器为例,我的有线网卡接口名为 eth0, 无线网卡接口名是 wlan0. 新建的聚合接口名会是 bond0.

系统信息

1
2
3
$ uname -a

Linux armbian 6.1.159-happy-new-year #1 SMP Wed Dec 31 14:07:28 UTC 2025 aarch64 GNU/Linux

加载 bonding 模块

1
2
3
sudo modprobe bonding
lsmod | grep bonding
echo "bonding" >> /etc/modules

interfaces 设置

eth0 设置

armbian 安装 pve 后,eth0 就已经变成 manual. 无须修改。

# /etc/network/interfaces

auto eth0
iface eth0 inet manual

wlan0 设置

添加 wlan0 的设置。

# /etc/network/interfaces

auto wlan0
iface wlan0 inet manual
        wpa-ssid "wifissidqwe123"
        wpa-psk "wifipskasdzxc"
        metric 666

bond0 设置

添加 bond0 的设置。

  • bond-slaves 填写被聚合网卡接口名。
  • bond-mode 填写 bond 模式。我需要的是 active-backup, 因为我这个无线网卡有问题,只有 2.4Ghz,速度慢,还会断流、会丢包,仅作为备用。
  • bond-primary 填写主要接口,即流量优先从这个口传输。
  • bond-miimon 不知道是啥,pve 添加上去的值,不管它,能用就行。
# /etc/network/interfaces

auto bond0
iface bond0 inet manual
        bond-slaves eth0 wlan0
        bond-miimon 100
        bond-mode active-backup
        bond-primary eth0

vmbr0 设置

vmbr0 是 pve 默认的虚拟网桥,默认使用 eth0 作为网桥接口。这里改成我需要的 bond0.

1
2
3
4
5
6
# /etc/network/interfaces

auto vmbr0
iface vmbr0 inet static
-         bridge-ports eth0
+         bridge-ports bond0

完整的 interfaces 配置

仅供参考,不要直接复制粘贴。

警告

谨慎设置,小心失联!

# /etc/network/interfaces

# network interface settings; autogenerated
# Please do NOT modify this file directly, unless you know what
# you're doing.
#
# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto wlan0
iface wlan0 inet manual
        wpa-ssid "wifissidqwe123"
        wpa-psk "wifipskasdzxc"
        metric 666

auto bond0
iface bond0 inet manual
        bond-slaves eth0 wlan0
        bond-miimon 100
        bond-mode active-backup
        bond-primary eth0

auto vmbr0
iface vmbr0 inet static
        address 192.168.666.555/24
        gateway 192.168.666.1
        dns-nameservers 192.168.666.1
        bridge-ports bond0
        bridge-stp off
        bridge-fd 0
        hwaddress ether 84:c6:4d:ef:12:47

应用设置

我的设备没有显示接口,为了防止意外,我插了额外的一张 USB 无线网卡并配置好联网,以免失联。

在确保安全的前提下,重启 pve 主机。

不出意外的话应该不出意外。我的 pve 主机重启后可以正常联网,在我的 openwrt 路由器上可以看到 pve 主机对应的 lan 口处于启用状态, pve 主机也连接到 Wi-Fi 网络中。

测试

测试 bond 是否能够正常切换网卡,可以使用另一台设备持续 ping pve 主机, 如:

  • ping -i 1 -W 1 192.168.666.555
  • ping -i 1 -W 1 192.168.666.555 -A

然后插、拔网线,查看 pve 主机是否有回应 ping。

例如:

我在 seq=10 时,断开了 pve 主机网线,随即看到 ping 的回应停顿了一下,随后延迟变大。

seq=20 左右,重新插上了网线,ping 回应没有停顿,过了一会,延迟变小。

通常来说,无线网卡的延迟大于有线网卡。因此在我的这个案例中,借助 ping 工具即可简单地观测 bond 网卡的切换情况。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$ ping -i 1 -W 1 192.168.666.555

PING 192.168.666.555 (192.168.666.555): 56 data bytes
64 bytes from 192.168.666.555: seq=0 ttl=64 time=1.187 ms
64 bytes from 192.168.666.555: seq=1 ttl=64 time=0.816 ms
64 bytes from 192.168.666.555: seq=2 ttl=64 time=0.897 ms
64 bytes from 192.168.666.555: seq=3 ttl=64 time=0.928 ms
64 bytes from 192.168.666.555: seq=4 ttl=64 time=0.992 ms
64 bytes from 192.168.666.555: seq=5 ttl=64 time=0.980 ms
64 bytes from 192.168.666.555: seq=6 ttl=64 time=0.970 ms
64 bytes from 192.168.666.555: seq=7 ttl=64 time=0.917 ms
64 bytes from 192.168.666.555: seq=8 ttl=64 time=1.050 ms
64 bytes from 192.168.666.555: seq=9 ttl=64 time=0.917 ms
64 bytes from 192.168.666.555: seq=10 ttl=64 time=0.947 ms
64 bytes from 192.168.666.555: seq=12 ttl=64 time=6.971 ms
64 bytes from 192.168.666.555: seq=13 ttl=64 time=3.994 ms
64 bytes from 192.168.666.555: seq=14 ttl=64 time=4.845 ms
64 bytes from 192.168.666.555: seq=15 ttl=64 time=4.862 ms
64 bytes from 192.168.666.555: seq=16 ttl=64 time=1.659 ms
64 bytes from 192.168.666.555: seq=17 ttl=64 time=1.638 ms
64 bytes from 192.168.666.555: seq=18 ttl=64 time=9.053 ms
64 bytes from 192.168.666.555: seq=19 ttl=64 time=3.115 ms
64 bytes from 192.168.666.555: seq=20 ttl=64 time=6.334 ms
64 bytes from 192.168.666.555: seq=21 ttl=64 time=7.020 ms
64 bytes from 192.168.666.555: seq=22 ttl=64 time=4.329 ms
64 bytes from 192.168.666.555: seq=23 ttl=64 time=1.063 ms
64 bytes from 192.168.666.555: seq=24 ttl=64 time=0.906 ms
64 bytes from 192.168.666.555: seq=25 ttl=64 time=0.920 ms
64 bytes from 192.168.666.555: seq=26 ttl=64 time=0.844 ms
64 bytes from 192.168.666.555: seq=27 ttl=64 time=0.896 ms
64 bytes from 192.168.666.555: seq=28 ttl=64 time=0.855 ms
64 bytes from 192.168.666.555: seq=29 ttl=64 time=0.918 ms
64 bytes from 192.168.666.555: seq=30 ttl=64 time=0.900 ms
Built with Hugo
Theme Stack designed by Jimmy