V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
king1688888888
V2EX  ›  Linux

请教关于 Linux 双网卡绑定的细节

  •  
  •   king1688888888 · 2020-02-17 20:12:48 +08:00 · 3531 次点击
    这是一个创建于 1500 天前的主题,其中的信息可能已经有所发展或是发生改变。
    参考教程,目前已经实现双网卡绑定,使用 mode1 主备模式,拔掉活动网卡后,备用网卡会接管,接管后可以正常 ping 通。但有几个问题,想稍微深入了解一下,烦请大神们解惑。


    1.配置好双网卡首次 service network restart 命令后,通过命令:cat /proc/net/bonding/bond0

    可以看到活动网卡是 eth1:

    Currently Active Slave:eth1

    eth1、eth2 真实 MAC 如下:

    eth1 MAC:00:50:56:2b:1a:02
    eth2 MAC:00:50:56:22:0d:1b

    再通过命令:ip a

    发现 bond0、eth1、eth2 的 MAC 地址都变成了 00:50:56:2b:1a:02,为什么会变 eth1 的 MAC,而不是 eth2 的 MAC ?默认是按 ethX 顺序来的吗?

    2.eth1 活动网卡被拔了网线,eth2 备用网卡接管,一秒内故障转移成功,可以 ping 通。

    此时通过命令:cat /proc/net/bonding/bond0

    可以看到活动网卡变成是 eth2:

    Currently Active Slave:eth2

    再通过命令:ip a

    发现 bond0、eth1、eth2 的 MAC 地址怎么还是 00:50:56:2b:1a:02 (即 eth1 )?网线都拔了,eth1 都是 down 状态,怎么还和 eth1 扯上关系。
    13 条回复    2020-02-19 09:28:54 +08:00
    Xusually
        1
    Xusually  
       2020-02-17 20:21:05 +08:00   ❤️ 3
    这是 bond 的 failover 模式默认行为。fail_over_mac 的默认值是:none,可选 active

    详见:
    https://www.kernel.org/doc/Documentation/networking/bonding.txt
    fail_over_mac

    Specifies whether active-backup mode should set all slaves to
    the same MAC address at enslavement (the traditional
    behavior), or, when enabled, perform special handling of the
    bond's MAC address in accordance with the selected policy.

    Possible values are:

    none or 0

    This setting disables fail_over_mac, and causes
    bonding to set all slaves of an active-backup bond to
    the same MAC address at enslavement time. This is the
    default.

    active or 1

    The "active" fail_over_mac policy indicates that the
    MAC address of the bond should always be the MAC
    address of the currently active slave. The MAC
    address of the slaves is not changed; instead, the MAC
    address of the bond changes during a failover.
    king1688888888
        2
    king1688888888  
    OP
       2020-02-17 21:01:26 +08:00
    @Xusually 多谢大神指点!经过测试,添加 fail_over_mac=1 后,确实 bond0 的 MAC 变成了活动网卡的 MAC。
    Xusually
        3
    Xusually  
       2020-02-17 21:07:02 +08:00
    @king1688888888 不客气。
    上面我没贴完整,还有一个:follow or 2,具体你看下我发的 URL 对应的部分。都有对应的最佳使用场景,和 bond 所在的网络环境和网卡设备条件有关。

    follow or 2

    The "follow" fail_over_mac policy causes the MAC
    address of the bond to be selected normally (normally
    the MAC address of the first slave added to the bond).
    However, the second and subsequent slaves are not set
    to this MAC address while they are in a backup role; a
    slave is programmed with the bond's MAC address at
    failover time (and the formerly active slave receives
    the newly active slave's MAC address).

    This policy is useful for multiport devices that
    either become confused or incur a performance penalty
    when multiple ports are programmed with the same MAC
    address.
    king1688888888
        4
    king1688888888  
    OP
       2020-02-17 21:10:04 +08:00
    @Xusually 还想请教大神一个问题,是关于双网卡故障转移与 NetworkManager 冲突的问题,eth1、eth2 的配置里,我没有加 NM_CONTROLLED=yes 这个参数,按理说就不受 NetworkManager 影响。实测发现,停用了 NetworkManager,故障转移正常。但开启了 NetworkManager 之后,故障转移失败。针对这个问题,请问可以发一下官方链接说明吗?我现在还不太懂找官方资料学习。
    king1688888888
        5
    king1688888888  
    OP
       2020-02-17 21:12:26 +08:00
    @Xusually 网上都只说停用 NetworkManager 就对了,省得麻烦,但想深入了解一下原因。
    Xusually
        6
    Xusually  
       2020-02-17 21:36:19 +08:00
    @king1688888888 如果你有 NetworkManger,并且你不想它来接管,你需要显式指定 NM_CONTROLLED=NO 才有意义。假定你没有 NetworkManager,你指定不指定都只会加载 if-cfg 自己的配置。

    这个倒不是默认行为的问题,道理很简单:
    如果你没有显式的声明说我不接受 NetworkManager 的话,你有启动 NM,那么 NM 来检查你的 if 脚本配置,没看到这个,它就会来配置网络。
    如果你有显式的拒绝,它就不来干涉。
    如果你没有 NM,那就无所谓。

    为了你配置的可维护性,建议直接指定 NM_CONTROLLED=NO
    king1688888888
        7
    king1688888888  
    OP
       2020-02-17 22:59:33 +08:00
    @Xusually 谢谢!
    gearfox
        8
    gearfox  
       2020-02-17 23:07:24 +08:00
    为什么不使用对 networkmanger 支持更好的 Teaming?
    xmr68yahoo
        9
    xmr68yahoo  
       2020-02-18 04:09:11 +08:00
    我感觉同 MAC 是没有问题的。
    类似于 VRRP

    如果双网卡的话 LACP 可以使带宽翻倍,网卡负载分担,但需对段交换机支持。
    king1688888888
        10
    king1688888888  
    OP
       2020-02-18 08:57:12 +08:00
    @gearfox 谢谢分享,我的测试环境是 RHEL6.10 ,也曾查阅过一些技术分享,Teaming 似乎更适合应用在 RHEL7 系列。
    king1688888888
        11
    king1688888888  
    OP
       2020-02-18 09:02:26 +08:00
    @xmr68yahoo 我目前的阶段只会参考教程去配置,虽然表面是成功了,但很多现象我无法用网络知识理论给自己解释。比如我都拔网线了,以我的理解就是这张网卡都没在工作了,怎么还会用到这网卡的 MAC 去通信。
    xmr68yahoo
        12
    xmr68yahoo  
       2020-02-18 15:22:52 +08:00
    @king1688888888
    首先要看 MAC 用来干嘛,每次 MAC 变动,都会在二层网络中触发 ARP 更新
    如果 MAC 变动,同时也要向 DHCP 服务器获取新的 IP 地址,这样会造成业务中断。
    如果路由或者交换机做了 MAC 绑定或者 ARP 安全策略,你会更麻烦。
    king1688888888
        13
    king1688888888  
    OP
       2020-02-19 09:28:54 +08:00
    @xmr68yahoo 是的,所以在麻烦来临前,我必须先弄明白 bond 一些原理。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5455 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:03 · PVG 16:03 · LAX 01:03 · JFK 04:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.