您的位置:首页 > 其它

auto to change IP address script

2012-05-16 15:04 316 查看
#!/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

本文出自 “tony” 博客,请务必保留此出处http://tonyzeng.blog.51cto.com/406650/864886
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: