1.1、添加双网卡,正常工作时他们会共同传输数据,使得网络传输的速度更快,mode6模式即使有一块网卡出现了故障,另一块会自动顶替上去,保证数据传输不会中断

1.2、网卡绑定驱动的三种模式 mode0 mode1 mode6

    mode0:(平衡负载模式):平时两块网卡均工作,且自动备援,但需要在与服务器本地网卡相连的交换机设备上进行端口聚合来支持绑定技术

    mode1:(自动备援模式):平时只有一块网卡工作,在它故障后自动替换为另外的网卡

    mode6:(平衡负载模式):平时两块网卡均工作,且自动备援,无需交换机设备提供辅助支持

1.3、双网卡的mode6模式配置环境

    环境:CentOS7.5

        # cat /etc/redhat-release

        CentOS Linux release 7.5.1804 (Core)

1.4、配置双网卡的mode6模式

    为服务器或虚拟机添加双网卡,服务器内网或外网,虚拟机网卡添加相同的模式桥接或nat

    配置过程:

    配置网卡1:ens33

        cd /etc/sysconfig/network-scripts/

        vim ifcfg-ens33

            DEVICE=ens33

            BOOTPROTO=static

            ONBOOT=yes

            MASTER=bond0

            SLAVE=yes

            USERCTL=no

    配置网卡2:ens36

        cd /etc/sysconfig/network-scripts/

        vim ifcfg-ens36

            DEVICE=ens36

            BOOTPROTO=static

            ONBOOT=yes

            MASTER=bond0

            SLAVE=yes

            USERCTL=no

    配置网卡bond0

        cd /etc/sysconfig/network-scripts/

        vim ifcfg-bond0

            DEVICE=bond0

            BONDING_OPTS="mode=6 miimon=100"

            BOOTPROTO=static

            ONBOOT=yes

            IPADDR=192.168.1.200

            NETMASK=255.255.255.0

            GATEWAY=192.168.1.1

            DNS1=192.168.1.1

            DNS2=114.114.114.114

            USERCTL=no

    在创建一个文件并写入一行配置

        vim /etc/modprobe.d/bonding.conf

            alias bond0 bonding

    进行检查是否加载了 bonding 模块

        # lsmod |grep bonding

        bonding               149864  0

    如果没有加载,进行加载

        modprobe bonding

    重启网卡

        systemctl restart network

1.5、检查配置情况

    # ifconfig

    bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500

            inet 192.168.1.200  netmask 255.255.255.0  broadcast 192.168.1.255

            ether 00:0c:29:b5:51:e8  txqueuelen 1000  (Ethernet)

            RX packets 2410  bytes 212984 (207.9 KiB)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 4708  bytes 367636 (359.0 KiB)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    ens33: flags=6147<UP,BROADCAST,SLAVE,MULTICAST>  mtu 1500

            ether 00:0c:29:b5:51:de  txqueuelen 1000  (Ethernet)

            RX packets 2004  bytes 182078 (177.8 KiB)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 928  bytes 144401 (141.0 KiB)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    ens36: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500

            ether 00:0c:29:b5:51:e8  txqueuelen 1000  (Ethernet)

            RX packets 2976  bytes 262465 (256.3 KiB)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 4708  bytes 367636 (359.0 KiB)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

            inet 127.0.0.1  netmask 255.0.0.0

            inet6 ::1  prefixlen 128  scopeid 0x10<host>

            loop  txqueuelen 1000  (Local Loopback)

            RX packets 353  bytes 101528 (99.1 KiB)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 353  bytes 101528 (99.1 KiB)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

            inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

            ether 52:54:00:2e:2f:38  txqueuelen 1000  (Ethernet)

            RX packets 0  bytes 0 (0.0 B)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 0  bytes 0 (0.0 B)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看网卡流量信息

    cat /proc/net/bonding/bond0

找一台机器进行ping,并断掉本机其中一块网卡观察是否正常接管

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    请求超时。

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64

    来自 192.168.1.200 的回复: 字节=32 时间<1ms TTL=64