Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> redhat linux下更改網卡邏輯名的腳本

redhat linux下更改網卡邏輯名的腳本

日期:2017/2/7 14:37:41      編輯:Linux教程
 

#!/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

將上面的代碼復制到一個文件,changnet.sh文件,將其設置成可執行。

執行的方法是 changnet.sh 0 1 (這個是將eth0改成eth1)

Copyright © Windows教程網 All Rights Reserved