#!/bin/bash

 

 

read -p "network driver ( eth0 | eth1 ) :" network

 

 

echo -n "It's checking"

/sbin/ifdown "$network"

/sbin/ifup "$network"

for i in `seq 6`

do

 echo -en "."

 sleep 1

done

echo

eth="/etc/sysconfig/network-scripts/ifcfg-$network"

driver=`ifconfig eth0 |grep 'UP'| awk '{print $1}'`

if [ "$driver" = "UP" -a "$network" = eth0 ]; then

echo "you can setup netowrk ( eth0 )"

echo

echo "**********your $network link is ok**********"

elif [ "$driver" = "UP" -a "$network" = eth1 ]; then

echo "**************you can setup network ( eth1 )**********"

echo

echo "***********your $network link is ok********"

else echo  "your network have problem or you must input right information,please check !!!!!!!!!!!!!!!!!!!!!!!!!!!"

exit 1

fi

 

path="/etc/sysconfig/network-scripts/ifcfg-$network"

cat "$path" > /root/ifcfg-$network

read -p "please input ( dhcp  | static ) :" te

echo "ONBOOT=yes" > $path

echo "TYPE=Ethernet" >> $path

echo "DEVICE=eth0" >> $path

if [ $te = "dhcp" ]; then

echo "BOOTPROTO=$te" >> $path

/etc/init.d/network restart

elif [ "$te" = "static" ]; then

read -p "please input ip address:" ip

echo "IPADDR=$ip" >> $path

read -p  "please input netmask : " netmask

echo "NETMASK=$netmask" >> $path

echo "setup done"

echo "************will be restart netowrk********************"

/etc/init.d/network restart

else

echo "you must be input again (dhcp | static )!!!!!!!!!!!!!!!!!!!!!!!11"

sh $0

fi