#!/bin/bash
####################
#Author:jncheng #
#Vsersion:20150402 #
####################
source /etc/profile
######################################################################################################
#
#List the system eth's Mac-address
######################################################################################################
echo "This MAC-Address is in file /etc/udev/rules.d/70-persistent-net.rules"
i=0
while [ $i -lt 5 ]
do
grep eth$i /etc/udev/rules.d/70-persistent-net.rules > /root/mac.txt
if [ $? = 0 ]; then
HWADDR2=$(awk '{print $4}' /root/mac.txt |awk -F == '{print $2}' |awk -F \" '{print $2}')
ETHNUM=$(awk '{print $7}' mac.txt |awk -F = '{print $2}' |awk -F \" '{print $2}')
echo "$ETHNUM MAC is $HWADDR2"
else
echo "Can't find other eth"
break
fi
i=$[i+1]
done
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
### , MAC 。 , MAC 。 MAC 。
echo "MAC-Address 00:50:56:ae:80:b8 Can't Use!!!!!!!!!!!!!!!!!!!!"
echo ""
#########################################################################################################
#Modify the IP and MAC addresss #
#########################################################################################################
read -p "Please input which eth number you will modify(0-4):" input_ethnum
grep -vi 00:50:56:AE:80:B8 /etc/udev/rules.d/70-persistent-net.rules |grep eth$input_ethnum > /root/mac.txt
ethnumber=$(awk '{print $7}' mac.txt |awk -F = '{print $2}' |awk -F \" '{print $2}')
read -p "Please Input IP:" IP
read -p "Please Input Gateway:" GATE
read -p "Please Input Prefix:" PRE
cd /etc/sysconfig/network-scripts
if [ -e ifcfg-eth0 ]; then
grep -v ^IPADDR ifcfg-eth0 |grep -v ^ONBOOT|grep -v ^NAME |grep -v ^DEVICE |grep -v ^PREFIX |grep -v ^GATEWAY |grep -v ^HWADDR > /root/ifcfg.txt
else
grep -v ^IPADDR ifcfg-eth1 |grep -v ^ONBOOT|grep -v ^NAME |grep -v ^DEVICE |grep -v ^PREFIX |grep -v ^GATEWAY |grep -v ^HWADDR > /root/ifcfg.txt
fi
sed -i '3a\GATEWAY='$GATE'' /root/ifcfg.txt
sed -i '3a\PREFIX='$PRE'' /root/ifcfg.txt
sed -i '3a\IPADDR='$IP'' /root/ifcfg.txt
sed -i '1a\DEVICE='$ethnumber'' /root/ifcfg.txt
sed -i '1a\ONBOOT=yes' /root/ifcfg.txt
HWADDR=$(awk '{print $4}' /root/mac.txt |awk -F == '{print $2}' |awk -F \" '{print $2}')
sed -i '3a\HWADDR='$HWADDR'' /root/ifcfg.txt
cp ifcfg-$ethnumber ifcfg-$ethnumber.bak
cp /root/ifcfg.txt ifcfg-$ethnumber
echo "Restart the networking... "
service network restart&&echo "Modify is scuefull"||echo "Modify is failed"