redhat linux下更改网卡逻辑名的脚本
时间:2010-11-08 来源:wood016
redhat linux下更改网卡逻辑名的脚本
将代码复制到一个文件,changnet.sh文件,将其设置成可执行。
执行的方法是 changnet.sh 0 1 (这个是将eth0改成eth1)
=======================以下是脚本=======================
#!/bin/bash
#this scripts will change your network card logic name!
#copy this scrips input your /bin,named with changnet.sh
#chmod +x /bin/changnet.sh
#usage:changnet.sh firstcardnumber secendcardnumber
#create date:2010/8/18
#auth:Jarson(at)gmail.com
#stop nic
ifdown eth$1
ifdown eth$2
#rename network card configure file !
cd /etc/sysconfig/network-scripts
sed -i -e "s/eth$1/eth$2/" ifcfg-eth$1
sed -i -e "s/eth$2/eth$1/" ifcfg-eth$2
mv ifcfg-eth$1 ifcfg-eth$2.tmp
mv ifcfg-eth$2 ifcfg-eth$1
mv ifcfg-eth$2.tmp ifcfg-eth$2
#switch alias in modprobe.conf
DRIVER1=`grep eth$1 /etc/modprobe.conf|awk '{print $3}'`
DRIVER2=`grep eth$2 /etc/modprobe.conf|awk '{print $3}'`
if
[ $DRIVER1 != $DRIVER2 ]
then
sed -e "/alias eth$1/d" -e "/alias eth$2/d" /etc/modprobe.conf>/etc/modprobe.conf.tmp.1
echo "alias eth$1 $DRIVER2">>/etc/modprobe.conf.tmp.1
echo "alias eth$2 $DRIVER1">>/etc/modprobe.conf.tmp.1
rm /etc/modprobe.conf
mv /etc/modprobe.conf.tmp.1 /etc/modprobe.conf
else
:
fi
=========================END===========================
将上面的代码复制到一个文件,changnet.sh文件,将其设置成可执行。
执行的方法是 changnet.sh 0 1 (这个是将eth0改成eth1)