首页 > 文章 > centos7--shell脚本自动实现bond配置-第二版

centos7--shell脚本自动实现bond配置-第二版

#!/bin/bash
#定义函数
function bond0()
{
cat > /etc/sysconfig/network-scripts/ifcfg-bond0 <<EOF
DEVICE=bond0
TYPE=bond
NAME=bond0
BONDING_MASTER=yes
BOOTPROTO=static
USERCTL=no
ONBOOT=yes
IPADDR=$bond0_ipaddr
PREFIX=24
BONDING_OPTS="mode=4 miimon=100"
EOF
cat > /etc/sysconfig/network << EOF
GATEWAY=$bond0_gateway
EOF
}
function eth1()
{
cat > /etc/sysconfig/network-scripts/ifcfg-$ETH1 <<EOF
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$ETH1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
}

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

时间:2019-05-16 01:23:44阅读(32)
联系我们 - 留言反馈
© 2017 版权所有 鲁ICP备17052893号