将网卡em1、em2绑定为bond0
[root@localhost network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
TYPE=bond
ONBOOT=yes
IPADDR=100.100.31.203
NETMASK=255.255.255.0
GATEWAY=100.100.31.1
DNS1=192.168.55.55
USERCTL=no
BONDING_MASTER=yes
BONDING_OPTS="miimon=200 mode=1"
[root@localhost network-scripts]# cat ifcfg-em1
TYPE=Ethernet
BOOTPROTO=none
DEVICE=em1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@localhost network-scripts]# cat ifcfg-em2
TYPE=Ethernet
BOOTPROTO=none
DEVICE=em2
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@localhost network-scripts]#
脚本:
#!/bin/bash
#
# Description: This is sysytem optimization scripts about centos !
################################################################
# Author:tommy xiao
# QQ: 610000107
# Date: 2019.07.15
################################################################
# Variable settings
network_path="/etc/sysconfig/network-scripts/ifcfg-"
bond0="/etc/sysconfig/network-scripts/ifcfg-bond0"
eth0="em1"
eth1="em2"
if [ -z "$4" ];then
echo -e "\033[40;33mUsage: /bin/bash bond0.sh ipaddr netmask gatewat dns1\n\033[40;37m"
exit 1
fi
if [ -f $bond0 ];then
echo -e "\033[40;31mbond0 already exists!!!\n\033[40;37m"
exit 2
else
cat > $bond0 <
DEVICE=bond0
BOOTPROTO=static
TYPE=bond
ONBOOT=yes
IPADDR=$1
NETMASK=$2
GATEWAY=$3
DNS1=$4
USERCTL=no
BONDING_MASTER=yes
BONDING_OPTS="miimon=200 mode=1"
EOF
cat > $network_path$eth0 <
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$eth0
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
cat > $network_path$eth1 <
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$eth1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
fi
if [ $? -eq 0 ];then
systemctl restart network.service && echo -e "\033[40;32mbond0 Configuration Successful!!!\n\033[40;37m"
else
echo -e "\033[40;32mbond0 Configuration failed!!!\n\033[40;37m"
fi