歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> redhat linux下更改網卡邏輯名的腳本

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

日期:2017/3/2 10:02:33   编辑:關於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 © Linux教程網 All Rights Reserved