function eth2()
{
cat > /etc/sysconfig/network-scripts/ifcfg-$ETH2 <<EOF
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$ETH2
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
}
#加载bonding模块
modprobe bonding
#获取基本信息
echo -n "请输入需要绑定第一个网卡名称(如:eth1):"
read ETH1
echo -n "请输入需要绑定第二个网卡名称(如:eth2):"
read ETH2
echo -n "请输入bond0IP地址:"
read bond0_ipaddr
echo -n "请输入bond0网关地址:"
read bond0_gateway
#确定网卡端口是否是万兆
a=$(ethtool $ETH1 |grep ‘Supported ports‘ |awk ‘{print $(NF-1)}‘)
b=$(ethtool $ETH2 |grep ‘Supported ports‘ |awk ‘{print $(NF-1)}‘)
if [ $a = $b ]
then
bond0
eth1
eth2
else
echo "网卡非万兆,请重新运行程序"
bash bond.sh
fi
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
systemctl restart network.service
ping $bond0_gateway -c 1
centos7--shell脚本自动实现bond配置-第二版
原文:https://blog.51cto.com/luojiutian/2395101