CentOS7 双网卡配置部署bond0

#!/bin/bash

IPADDR="192.168.128.123"
NETMASK="255.255.255.0"
GATEWAY="192.168.128.1"
DEVNAME1="em1"
DEVNAME2="em2"
NETDIR="/etc/sysconfig/network-scripts"


if [ ! -f "$NETDIR/ifcfg-$DEVNAME1.bak" ]; then
    cp $NETDIR/ifcfg-$DEVNAME1{,.bak}
fi

if [ ! -f "$NETDIR/ifcfg-$DEVNAME2.bak" ]; then
    cp $NETDIR/ifcfg-$DEVNAME2{,.bak}
fi

cat > $NETDIR/ifcfg-bond0 <<EOF
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=$IPADDR
NETMASK=$NETMASK
GATEWAY=$GATEWAY
EOF

cat > $NETDIR/ifcfg-$DEVNAME1 <<EOF
DEVICE=$DEVNAME1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF

cat > $NETDIR/ifcfg-$DEVNAME2 <<EOF
DEVICE=$DEVNAME2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF

echo "ifenslave bond0 $DEVNAME1 $DEVNAME2" >> /etc/rc.d/rc.local

cat > /etc/modprobe.d/dist.conf <<EOF
alias bond0 bonding
options bond0 miimon=100 mode=1
EOF

systemctl restart network.service

exit 0

 

posted @ 2017-12-27 10:59  追阳  阅读(3856)  评论(0编辑  收藏  举报