Wednesday, June 18, 2008

Script for creating bonded interfaces

Usage:
bond.sh interface1 interface2 bondname IP boradcastIP netmask network mode link_monitoring_frequency(miimon)

./bond.sh eth5 eth6 bond0 192.168.0.100 192.168.0.255 255.255.255.0 192.168.0.0 6 100

Copy the text below to create the bond.sh script

#! /bin/sh

if [ $# -ne 9 ]; then
printf "Usage:\nbond.sh interface1 interface2 bondname IP boradcastIP netmask network mode link_monitoring_frequency(miimon)\n"
printf "eg: bond.sh eth5 eth6 bond0 192.168.0.100 192.168.0.255 255.255.255.0 192.168.0.0 6 100\n"
exit 0
fi

printf "\t\t*************** Bonded interface script ***************\n"
printf "\t\t*************** Author : Asanga Pradeep ***************\n"

if [ -f /etc/sysconfig/network-scripts/ifcfg-$1 ]; then

if [ -f /etc/sysconfig/network-scripts/ifcfg-$2 ]; then

mv /etc/sysconfig/network-scripts/ifcfg-$1 /root/ifcfg-$1
mv /etc/sysconfig/network-scripts/ifcfg-$2 /root/ifcfg-$2
echo "Original files moved to /root"
else
echo "No "$2" found"
exit 0
fi


else
echo "No "$1" found"
exit 0
fi

#creating bond ---------------------------------------------------------------

echo "creating bond " $3
touch /etc/sysconfig/network-scripts/ifcfg-$3

echo "DEVICE="$3 >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "BROADCAST="$5 >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "IPADDR="$4 >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "IPV6ADDR=" >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "IPV6PREFIX=" >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "IPV6_AUTOCONF=yes" >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "NETMASK="$6 >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "NETWORK="$7 >> /etc/sysconfig/network-scripts/ifcfg-$3
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-$3

#creating first eth -------------------------------------------------------------------

echo "creating "$1

touch /etc/sysconfig/network-scripts/ifcfg-$1

echo "DEVICE="$1 >> /etc/sysconfig/network-scripts/ifcfg-$1
echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-$1
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-$1
echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-$1
echo "MASTER=$3" >> /etc/sysconfig/network-scripts/ifcfg-$1
echo "SLAVE=yes" >> /etc/sysconfig/network-scripts/ifcfg-$1
echo "MTU=9000" >> /etc/sysconfig/network-scripts/ifcfg-$1


#creating second eth -------------------------------------------------------------------

echo "creating "$2
touch /etc/sysconfig/network-scripts/ifcfg-$2

echo "DEVICE="$2 >> /etc/sysconfig/network-scripts/ifcfg-$2
echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-$2
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-$2
echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-$2
echo "MASTER=$3" >> /etc/sysconfig/network-scripts/ifcfg-$2
echo "SLAVE=yes" >> /etc/sysconfig/network-scripts/ifcfg-$2
echo "MTU=9000" >> /etc/sysconfig/network-scripts/ifcfg-$2

#editng modprobe.conf

if [ -f /etc/modprobe.conf ]; then

cp /etc/modprobe.conf /etc/modprobe.conf.bak
echo "Original file backup as /etc/modprobe.conf.bak"
echo "alias "$3" bonding" >> /etc/modprobe.conf
echo "options "$3" mode="$8" miimon="$9 >> /etc/modprobe.conf
/sbin/modprobe bonding
else
echo "NO /etc/modprobe.conf found"
fi