首页 > 系统服务 > 详细

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

时间:2019-05-16 11:36:07      阅读:254      评论:0      收藏:0      [点我收藏+]
#!/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

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

原文:https://blog.51cto.com/luojiutian/2395101

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!