Easy script for creating bonded interfaces in RedHat

I had to create a bond1 on the machine I built once the build process was done. If you ever run into that situation, here is a quick script to make it easier. Look it over. It's crude, but works for now. I may put some string validation in later.

-enjoy

Usage: mkbond bond# slave1 slave2 ipaddress mask [ gateway ]


#!/bin/bash

usage()
{
echo "Usage: mkbond {bond#} {slave1} {slave2} {ipaddress} {mask} [ gateway ]"
exit 1
}

BOND=$1
SL1=$2
SL2=$3
IPADDR=$4
MASK=$5
GW=$6

[ -n "$1" ] || usage
[ -n "$2" ] || usage
[ -n "$3" ] || usage
[ -n "$4" ] || usage
[ -n "$5" ] || usage
[ $# -ge 5 ] || usage

echo "$1 $2 $3 $4 $5 $6"

# Build the bonding interface
echo "DEVICE=${BOND}
BONDING_OPTS="miimon=100 mode=active-backup primary=${SL1}"
ONPARENT=yes
BOOTPROTO=static
IPADDR=${IPADDR}
NETMASK=${MASK}
" > /etc/sysconfig/network-scripts/ifcfg-${BOND}
[ -n "$GW" ] && echo "GATEWAY=${GW}" >> /etc/sysconfig/network-scripts/ifcfg-${BOND}

# Build Slave 1
echo "DEVICE=${SL1}
ONBOOT=yes
SLAVE=yes
MASTER=${BOND}
HOTPLUG=no
BOOTPROTO=none
" > /etc/sysconfig/network-scripts/ifcfg-${SL1}

# Build Slave 2
echo "DEVICE=${SL2}
ONBOOT=yes
SLAVE=yes
MASTER=${BOND}
HOTPLUG=no
BOOTPROTO=none
" > /etc/sysconfig/network-scripts/ifcfg-${SL2}

# insert module info into /etc/modprobe.conf if it is not already there
if [ -f /etc/modprobe.conf ]
then
if ! grep ${BOND} /etc/modprobe.conf
then
echo "install ${BOND} /sbin/modprobe bonding -o ${BOND} miimon=100 mode=active-backup primary=${SL1}" >> /etc/modprobe.conf
fi
fi

exit 0

Comments

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.