CentOS7中宿主机配置多网卡绑定和建桥的方法

CentOS7中宿主机配置多网卡绑定和建桥的方法

(1)配置modprobe文件,内容如下

cat /etc/modprobe.d/nicbond.conf

alias bond0 bonding

options bond0 mode=1 miimon=100

多网卡绑定可以有0-6 6模式

mode=0 多端口轮询发送数据包;

mode=1 主备模式;

mode=2 基于HASH算法发送数据包;

mode=3 每个接口上传输每个数据包,此模式提供了容错能力;

mode=4 基于(802.3ad) IEEE 802.3ad Dynamic link aggregation(IEEE 802.3ad 动态链接聚合),需要和交换机配合;

mode=5 每个网卡根据当前的负载(根据速度计算)分配外出流量;

mode=6 针对ipv4做了优化;

(2) 挂载bonding模块

modprobe bonding

(3) 配置多网卡绑定接口

服务器有4个网口:

enp3s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

       ether 1c:c1:de:1e:a1:f2 txqueuelen 1000 (Ethernet)

       RX packets 6716921 bytes 745694715 (711.1 MiB)

       RX errors 0 dropped 0 overruns 0 frame 0

       TX packets 689079 bytes 174181455 (166.1 MiB)

       TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


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

       ether 1c:c1:de:1e:a1:f4 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


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

       ether 1c:c1:de:1e:a1:f6 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


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

       ether 1c:c1:de:1e:a1:f8 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

绑定enp4s0f0 enp4s0f1,先配置聚合接口:

cd /etc/sysconfig/network-scripts

cat ifcfg-bond0

DEVICE=bond0

ONBOOT=YES

BRIDGE=br1

配置 enp4s0f0:

cat ifcfg-enp4s0f0

HWADDR=1C:C1:DE:1E:A1:F6

TYPE=Ethernet

BOOTPROTO=none

NAME=enp4s0f0

UUID=2ae88bd4-5d49-42e8-b247-702738c954ac

ONBOOT=yes

MASTER=bond0

SLAVE=yes

配置 enp4s0f1:

cat ifcfg-enp4s0f1

HWADDR=1C:C1:DE:1E:A1:F8

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

NAME=enp4s0f1

UUID=d1a335d6-dec4-4ba2-aaea-0b7c14b653c6

ONBOOT=yes

MASTER=bond0

SLAVE=yes

(4) 配置虚拟网桥

cat ifcfg-br1

DEVICE=br1

TYPE=Bridge

IPADDR=192.168.20.200

NETMASK=255.255.255.0

ONBOOT=yes

重启网络,可以通过ifconfig命令查看结果:

systemctl restart network.service

ifconfig

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

       inet 192.168.20.200 netmask 255.255.255.0 broadcast 192.168.20.255

       ether 1a:bf:fc:5a:da:91 txqueuelen 0 (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

查看/proc/net/bonding/bond0可以看到绑定端口的状态:

cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: load balancing (round-robin)

MII Status: down

MII Polling Interval (ms): 0

Up Delay (ms): 0

Down Delay (ms): 0


你可能感兴趣的:(网卡)