Jump to content

主板是千兆网卡,插一张2.5g网卡,主备绑定或桥接能不能设置2.5g网卡为默认


Recommended Posts

又来自问自答了,找到一个相对理想的方法。

1. 设置网络开启绑定,开启桥接

1259910731_2023-04-26230935.png.d69611c3add15b1b3bb8a6a965dc64e0.png

2. 查看当前活动网卡接口

cat /sys/class/net/bond0/bonding/active_slave

3. 切换网卡接口,注意将’eth4‘更换为你想切换的接口名称

echo eth4 > /sys/class/net/bond0/bonding/active_slave

结束。

这样修改重启后又会恢复到eth0,在User Scripts添加脚本

#!/bin/bash

# 设定想要切换到的目标接口
e='eth4'

# 获取当前活动接口
i=`cat /sys/class/net/bond0/bonding/active_slave`
# 判断是否是想要的接口,如果是就结束
# 如果不是则继续判断是否要切换
if [ $i != $e ]
then
    # 判断目标接口是否连接
    i=`ethtool $e 2>&1 | grep -c "Link detected: yes"`
    # 如果目标接口已连接则切换到目标接口
    if [ $i -gt 0 ]
    then
        echo $e > /sys/class/net/bond0/bonding/active_slave
        echo '已切换到接口:'$e
    else
        echo '接口未连接,不切换。'
    fi
else
    echo '接口正确,不需要切换。'
fi

设定开机启动或定时启动,我设置的每10分钟执行一次。因为我看到有网友反映切换后过段时间系统会切回去。

参考帖子:BONDING 有办法改PRIMARY吗?

NETWORK BONDING: PRIMARY INTERFACE

话说我每次搜索中文关键字都没结果什么情况?

Edited by lvxj11
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...