无需 ifenslave 命令即可更改 Linux 网络绑定接口的活动从属设备

Mik*_*hik 2 linux bonding linux-networking iproute2

Linux 支持多个以太网网络接口的绑定,以实现额外的可靠性或负载平衡。

绑定驱动程序过去是通过命令配置的,该命令已被弃用(由iproute2工具包中的命令ifenslave取代),因此已从内核源代码中删除。ipifenslave

已弃用命令的一个特殊功能(我找不到现代等效命令)是更改绑定接口的活动从属设备(假设绑定接口在该模式下运行active-backup)。

例如,以下命令将eth0网卡设置为bond0接口的活动从属:

ifenslave -c bond0 eth0
ifenslave --change-active bond0 eth0
Run Code Online (Sandbox Code Playgroud)

有没有办法使用iproute2ip工具包中的命令或通过 sysfs 更改 Linux 绑定接口的活动从属设备?

Ant*_*lov 6

创建bonding接口的流程:

# create the bonding interface with active-backup mode
ip link add name bond0 type bond mode active-backup

# add the under laying interfaces
# the interface, that has been added first, will be active
ip link set master bond0 dev eth1
ip link set master bond0 dev eth0

# enable the bonding interface
ip link set up dev bond0
ip address add 192.168.100.1/24 dev bond0

# check the results: detailed info and statistics of bond0
ip -s -s -d link ls dev bond0

# check the state of ALL under laying interfaces
# with statistics and details 
ip -s -s -d link ls master bond0

# check the kernel logs
journalctl -kn 20
Run Code Online (Sandbox Code Playgroud)

要更改绑定设备的活动链路,您应该使用以下命令:

ip link set dev bond0 type bond active_slave eth0
Run Code Online (Sandbox Code Playgroud)

如果您收到类似错误,RTNETLINK answers: invalid argument请检查dmesg或 输出journalctl -k

有关选项的简要帮助,您可以使用ip link add type bond help命令。它适用于任何链接类型。

bond0您可以通过命令获取接口当前选项的所有值ip -d l ls dev bond0