Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1120938
  • 博文数量: 113
  • 博客积分: 2422
  • 博客等级: 大尉
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-25 17:54
文章分类
文章存档

2016年(1)

2014年(8)

2013年(7)

2012年(13)

2011年(42)

2010年(26)

2009年(6)

2008年(6)

2007年(4)

我的朋友

分类: LINUX

2010-11-08 14:06:40

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)

阅读(2186) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-08 15:25:11

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com