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

转载于:https://blog.51cto.com/luojiutian/2395101

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值