centos7双网卡绑定bond#yyds干货盘点#

关山初度尘未洗,策马扬鞭再奋蹄!这篇文章主要讲述centos7双网卡绑定bond#yyds干货盘点#相关的知识,希望能为你提供帮助。
centos7双网卡绑定bond 1.bond简介2.配置bond以双网卡为例
2.1.配置两块网卡配置信息

[root@k8s-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=none ONBOOT=yes DEVICE=ens33 MASTER=bond0 SLAVE=yes[root@k8s-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens37 TYPE=Ethernet BOOTPROTO=none ONBOOT=yes DEVICE=ens37 MASTER=bond0 SLAVE=yes

2.2.配置bond网卡信息
[root@k8s-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0 TYPE=Ethernet BOOTPROTO=none ONBOOT=yes DEVICE=bond0 IPADDR=192.168.81.210 NETMASK=255.255.255.0 GATEWAY=192.168.81.2 DNS=114.114.114.114

2.3.配置内核网卡驱动模式
[root@k8s-master ~]# vim /etc/modprobe.d/bond.conf alias bond0 bonding options bonding mode=6 miimon=200

2.4.重启网卡
[root@k8s-master ~]# systemctl restart network

2.5.查看bond是否生效
[root@k8s-master ~]# ifconfig bond0: flags=5187< UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 inet 192.168.81.210netmask 255.255.255.0broadcast 192.168.81.255 inet6 fe80::20c:29ff:fed5:a566prefixlen 64scopeid 0x20< link> ether 00:0c:29:d5:a5:66txqueuelen 1000(Ethernet) RX packets 811bytes 65115 (63.5 KiB) RX errors 0dropped 187overruns 0frame 0 TX packets 1574bytes 118007 (115.2 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0ens33: flags=6211< UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 00:0c:29:d5:a5:66txqueuelen 1000(Ethernet) RX packets 1851bytes 209289 (204.3 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 1857bytes 234505 (229.0 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0ens37: flags=6211< UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 00:0c:29:d5:a5:70txqueuelen 1000(Ethernet) RX packets 457bytes 39789 (38.8 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 753bytes 52110 (50.8 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0

3.自动化配置bond脚本【centos7双网卡绑定bond#yyds干货盘点#】使用方式:sh boun.sh 网卡模式 IP地址
[root@elk-1 ~/soft]# cat bound.sh #!/bin/bash #设置多网卡bond,实现网卡的高可用,提升网卡带宽 #此脚本需要传入两个参数 $1为bond模式$2为boundIP地址if [$# = 2 ] ; then#判断传入的参数是否为2个 #定义主机上网卡的名称变量 NAME1=eno1 NAME2=eno2 NAME3=eno3 NAME4=eno4#定义要写入网卡配置文件的网络参数 IPADDR=$2 NETMASK=255.255.240.0 GATEWAY=192.168.1.25 DNS=114.114.114.114 else echo "脚本使用错误!!!! 格式为:$PWD/$0 [ 0-6 ] ipaddr 例如: $PWD/$0 网卡模式 192.168.1.100" exit 1; fi#生成bond配置文件 echo "alias bond0 bonding options bonding mode=$1 miimon=200 " > /etc/modprobe.d/bonding.conf#判断第一个网卡是否存在,如果存在就生成第一个网卡的配置文件 if [ ! -z $NAME1 ] ; then echo "DEVICE=$NAME1 BOOTPROTO=none MASTER=bond0 SLAVE=yes" > /etc/sysconfig/network-scripts/ifcfg-$NAME1 fi#判断第二个网卡是否存在,如果存在就生成第二个网卡的配置文件 if [ ! -z $NAME2 ] ; then echo "DEVICE=$NAME2 BOOTPROTO=none MASTER=bond0 SLAVE=yes" > /etc/sysconfig/network-scripts/ifcfg-$NAME2 fi#判断第三个网卡是否存在,如果存在就生成第三个网卡的配置文件 if [ ! -z $NAME3 ] ; then echo "DEVICE=$NAME3 BOOTPROTO=none MASTER=bond0 SLAVE=yes" > /etc/sysconfig/network-scripts/ifcfg-$NAME3 fi#判断第四个网卡是否存在,如果存在就生成第四个网卡的配置文件 if [ ! -z $NAME4 ] ; then echo "DEVICE=$NAME4 BOOTPROTO=none MASTER=bond0 SLAVE=yes" > /etc/sysconfig/network-scripts/ifcfg-$NAME4 fi#生成bond配置文件 echo "DEVICE=bond0 BOOTPROTO=none ONBOOT=yes IPADDR=$IPADDR NETMASK=$NETMASK GATEWAY=$GATEWAY DNS1=$DNS " > /etc/sysconfig/network-scripts/ifcfg-bond0#重启网络服务 systemctldisable NetworkManager systemctlstop NetworkManager modprobe -r bonding modprobebonding service network restart#打印网络信息 echo "IPADDR=$IPADDR NETMASK=$NETMASK GATEWAY=$GATEWAY DNS1=$DNS "


    推荐阅读