Easy bond Interface

If you ever set up a bond interface on Linux you know it takes a few file editing. I got tired of doing this, please find my script below creating a bond interface. This is crafted for CentOS or RedHat but it might work on other distributions as well. Feel free to check out the git repo and improve it 😉

#!/bin/bash
#Created by: Laszlo Danielisz: https://github.com/danielisz/linux 
#

_usage() {

cat < /etc/sysconfig/network-scripts/ifcfg-bond0 << EOL
DEVICE=bond0
BONDING_OPTS="miimon=100 mode=active-backup primary=$INTERFACE1"
BONDING_MASTER=yes
BOOTPROTO=none
IPADDR=$IP
PREFIX=$MASK
GATEWAY=$GW
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=bond0
ONBOOT=yes
DOMAIN=vrt.sourcefire.com
IPV6INIT="NO"
IPV6_PRIVACY="NO"
IPV6_AUTOCONF="NO"
IPV6_FAILURE_FATAL="NO"
EOL

cat > /etc/sysconfig/network-scripts/ifcfg-$INTERFACE1 << EOL
TYPE=Ethernet
NAME=$INTERFACE1
UUID=$UUID1
DEVICE=$INTERFACE1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
IPV6INIT="NO"
IPV6_AUTOCONF="NO"
IPV6_DEFROUTE="NO"
IPV6_FAILURE_FATAL="NO"
IPV6_ADDR_GEN_MODE="NO
EOL

cat > /etc/sysconfig/network-scripts/ifcfg-$INTERFACE2 << EOL
TYPE=Ethernet
NAME=$INTERFACE2
UUID=$UUID2
DEVICE=$INTERFACE2
ONBOOT=yes
MASTER=bond0
SLAVE=yes
IPV6INIT="NO"
IPV6_AUTOCONF="NO"
IPV6_DEFROUTE="NO"
IPV6_FAILURE_FATAL="NO"
IPV6_ADDR_GEN_MODE="NO
EOL

}

case $2 in

    *[0-9])
	    INTERFACE1=$1
	    INTERFACE2=$2
            _makebond
            ;;
    *)
            _usage
            ;;
esac

Leave a Reply

Your email address will not be published. Required fields are marked *