系统环境:CentOS 7.4
将两块网卡eth0, eth1绑定成一块网卡bond0实现网口负载平衡和容错能力
bond0信息如下
bond0的IP地址:192.168.100.100/24
bond0的网关:192.168.100.1
bond0的主DNS:202.106.0.20
bond0的从DNS:8.8.8.8
#!/bin/bash # by: ZDF # Bond_IP_ADDR=192.168.100.100 Bond_NET_PREFIX=24 Bond_GAT_EWAY=192.168.100.1 Bond_DNS_1=202.106.0.20 Bond_DNS_2=8.8.8.8 Bond_Level=0 NetDevice_1=eth0 NetDevice_2=eth1 find /etc/sysconfig/network-scripts -iname ifcfg-* -not \( -iname "ifcfg-lo" -o -iname "*.bak" \) -exec mv {} {}.bak \; if [ $? -ne 0 ];then exit 3 fi touch /etc/sysconfig/network-scripts/ifcfg-bond$Bond_Level cat > /etc/sysconfig/network-scripts/ifcfg-bond$Bond_Level << EOF NAME=bond$Bond_Level DEVICE=bond$Bond_Level ONBOOT=yes TYPE=Ethernet BOOTPROTO=static IPADDR=$Bond_IP_ADDR PREFIX=$Bond_NET_PREFIX GATEWAY=$Bond_GAT_EWAY DNS1=$Bond_DNS_1 DNS2=$Bond_DNS_2 TYPE=Bond BONDING_MASTER=yes USERCTL=no BONDING_OPTS=“miimon=100 mode=$Bond_Level” EOF touch /etc/sysconfig/network-scripts/ifcfg-$NetDevice_1 cat > /etc/sysconfig/network-scripts/ifcfg-$NetDevice_1 << EOF NAME=$NetDevice_1 DEVICE=$NetDevice_1 ONBOOT=yes BOOTPROTO=none TYPE=Ethernet MASTER=bond$Bond_Level SLAVE=yes USERCTL=no EOF touch /etc/sysconfig/network-scripts/ifcfg-$NetDevice_2 cat > /etc/sysconfig/network-scripts/ifcfg-$NetDevice_2 << EOF NAME=$NetDevice_2 DEVICE=$NetDevice_2 ONBOOT=yes BOOTPROTO=none TYPE=Ethernet MASTER=bond$Bond_Level SLAVE=yes USERCTL=no EOF ifdown $NetDevice_1 ifup $NetDevice_1 ifdown $NetDevice_2 ifup $NetDevice_2 ifup bond$Bond_Level systemctl restart network.service echo echo -e "\033[32;1m$(cat /sys/class/net/bonding_masters)\033[m" cat /proc/net/bonding/bond$Bond_Level