centos7 bond绑定

将网卡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 <<EOF
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 <<EOF
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$eth0
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
cat > $network_path$eth1 <<EOF
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

centos7 bond绑定

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值