#!/bin/bash
em1_mac=`ifconfig em1 |grep 'HWaddr' |awk '{print $5}'`
em2_mac=`ifconfig em2 |grep 'HWaddr' |awk '{print $5}'`
em3_mac=`ifconfig em3 |grep 'HWaddr' |awk '{print $5}'`
em4_mac=`ifconfig em4 |grep 'HWaddr' |awk '{print $5}'`
em1="/etc/sysconfig/network-scripts/ifcfg-em1"
em2="/etc/sysconfig/network-scripts/ifcfg-em2"
em3="/etc/sysconfig/network-scripts/ifcfg-em3"
em4="/etc/sysconfig/network-scripts/ifcfg-em4"
ip_address=`ifconfig em1 |grep 'inet addr' |awk '{print $2}' |awk -F ":" '{print $2}'`
touch /etc/sysconfig/network-scripts/ifcfg-bond0
touch /etc/sysconfig/network-scripts/ifcfg-bond1
bond0="/etc/sysconfig/network-scripts/ifcfg-bond0"
bond1="/etc/sysconfig/network-scripts/ifcfg-bond1"
echo "DEVICE=em1" > $em1
echo "HWADDR=$em1_mac" >> $em1
echo "TYPE=Ethernet" >> $em1
echo "ONBOOT=yes" >> $em1
echo "SLAVE=yes" >> $em1
echo "MASTER=bond0" >> $em1
echo "BOOTPROTO=none" >> $em1
echo "DEVICE=em2" > $em2
echo "HWADDR=$em2_mac" >> $em2
echo "TYPE=Ethernet" >> $em2
echo "ONBOOT=yes" >> $em2
echo "SLAVE=yes" >> $em2
echo "MASTER=bond0" >> $em2
echo "BOOTPROTO=none" >> $em2
echo "DEVICE=em3" > $em3
echo "HWADDR=$em3_mac" >> $em3
echo "TYPE=Ethernet" >> $em3
echo "ONBOOT=yes" >> $em3
echo "SLAVE=yes" >> $em3
echo "MASTER=bond1" >> $em3
echo "BOOTPROTO=none" >> $em3
echo "DEVICE=em4" > $em4
echo "HWADDR=$em4_mac" >> $em4
echo "TYPE=Ethernet" >> $em4
echo "ONBOOT=yes" >> $em4
echo "SLAVE=yes" >> $em4
echo "MASTER=bond1" >> $em4
echo "BOOTPROTO=none" >> $em4
echo "DEVICE=bond0" > $bond0
echo "ONBOOT=yes" >> $bond0
echo 'BONDING_OPTS="miimon=100 mode=0"' >> $bond0
echo "BOOTPROTO=static" >> $bond0
echo "IPADDR=$ip_address" >> $bond0
echo "NETMASK=255.255.255.0" >> $bond0
echo "DEVICE=bond1" > $bond1
echo "ONBOOT=yes" >> $bond1
echo 'BONDING_OPTS="miimon=100 mode=0"' >> $bond1
echo "BOOTPROTO=static" >> $bond1