如何测试Linux主备模式(Active/Backup)绑定网卡(bond)接口
Alright, let's tackle this problem. You've got an Active/Backup bond (bond0) running with eth0 as the primary active slave, and you need to verify eth1's data path without messing up your live services. Here are the safest, non-intrusive ways to get this done:
First, let's confirm your current bond state to make sure we're working with the right setup. Run this command to check which slave is active and verify bond configuration:
cat /proc/net/bonding/bond0
Look for the "Active Slave" line (should be eth0) and confirm the mode is set to active-backup (mode=1).
Method 1: Temporarily Switch Active Slave to eth1 (Recommended)
This is the most straightforward approach since it uses the bond driver's native functionality, and the switchover is nearly instantaneous—most workloads won't notice any disruption.
Switch active slave to eth1:
Run this command to force the bond to use eth1 as the active interface:echo eth1 > /sys/class/net/bond0/bonding/active_slaveRe-run
cat /proc/net/bonding/bond0to confirm eth1 is now listed as the Active Slave.Test eth1's connectivity:
- Use
pingto verify basic reachability (specify bond0 as the interface to ensure traffic goes through the bond stack):ping -I bond0 <your-test-target-ip> - Use
tcpdumpon eth1 to confirm traffic is passing through it:
You should see ICMP (ping) packets or other test traffic flowing through eth1.tcpdump -i eth1 -n host <your-test-target-ip> - For throughput testing, use
iperf3with a remote server (bind to bond0 to use the bond interface):iperf3 -c <iperf-server-ip> -B <bond0-ip>
- Use
Switch back to eth0:
Once testing is done, revert to your original active slave with:echo eth0 > /sys/class/net/bond0/bonding/active_slaveNote: If your bond configuration has a
primaryparameter set (e.g., in your distro's network config file like/etc/sysconfig/network-scripts/ifcfg-bond0), the bond will automatically revert to eth0 after a reboot even if you forget to run this command.
Method 2: Test Link Health Without Switching Active Slave
If you just want to verify eth1's physical link and basic data path without sending production traffic through it, use these checks:
- Verify eth1's link state is up:
Look forip link show eth1UPin the output. - Use
ethtoolto check link details (speed, duplex, carrier status):ethtool eth1 - Send test traffic directly to eth1's MAC address to confirm physical path functionality:
First, get eth1's MAC withip link show eth1, then usearpingto send ARP requests through eth1 to your gateway:
This confirms eth1 can send and receive frames on the network.arping -I eth1 -c 5 <gateway-ip>
Key Notes
- Both methods avoid modifying permanent network configurations, so your setup will revert to normal if you reboot or restart the network service.
- The active slave switchover is designed to be seamless—most applications won't even notice the brief transition.
内容的提问来源于stack exchange,提问作者Zaboj Campula

