将电缆和无线网络接口 (RJ45/WLAN) 连接在一起,以定义一个虚拟(即绑定)网络接口(例如 bond0)。 只要连接了网线,它的接口(例如 eth0)就用于网络流量。如果你拔掉 RJ45 插头,ifenslave 会透明地切换到无线接口(例如 wlan0),而不会丢失任何网络包。
apt-get install ifenslave
重新连接网线后,ifenslave 切换回 eth0("故障转移模式")。 从外部视图来看,哪个接口处于活动状态并不重要。绑定设备提供自己的软件定义(即虚拟)MAC 地址,与 eth0 或 wlan0 的硬件定义 MAC 不同。
bash
▶ cat /etc/network/interfaces.d/bond0
auto bond0
iface bond0 inet static
address 192.168.0.100/24
netmask 255.255.255.0
network 192.168.0.0
bond-slaves none
bond-primary enp45s0
bond-mode active-backup
bond-miimon 100
bond-downdelay 200
bond-updelay 200
# Define slaves
auto enp45s0
iface enp45s0 inet manual
bond-master bond0
bond-primary enp45s0
bond-mode active-backup
# Define slaves
auto enp44s0
iface enp44s0 inet manual
bond-master bond0
bond-primary enp45s0
bond-mode active-backup
auto bond0.123
iface bond0.123 inet static
address 10.123.0.3
netmask 255.255.255.0
mtu 1500
vlan-raw-device bond0
post-up ifconfig bond0.123 mtu 1500
配置后重启:
bash
/etc/init.d/networking stop
/etc/init.d/networking start