修改centos7.x网卡名称

某些情况下需要多台服务器网卡名称保持一致,使用此脚本修改网卡名为传统显示方式,建议在系统安装后立即进行,使用前请自行测试
安装系统时TAB输入 net.ifnames=0 biosdevname=0 就可以实行同样效果

 

 

#vim changename.sh

#以下为脚本内容

#!/bin/sh

#author by huanjiming 2017/10/18

#This script modifies the network card name  like eth*



namelist=`ip add|grep 1500|awk -F "[ :]+" '{print $2}'`

i=0



for name in $namelist

do

echo "start modifying  $name"

cp   /etc/sysconfig/network-scripts/ifcfg-$name /etc/sysconfig/network-scripts/ifcfg-${name}.bak

mv /etc/sysconfig/network-scripts/ifcfg-$name /etc/sysconfig/network-scripts/ifcfg-eth$i

if [ $? -ne 0 ];then

echo "can't rename the $name configuration file name"

exit

fi

sed -i 's#'$name'#eth'$i'#g' /etc/sysconfig/network-scripts/ifcfg-eth$i

if [ $? -ne 0 ];then

echo "can't rename the DEVICE name"

exit

fi

sed -i 's#'UUID'#\#UUID#g' /etc/sysconfig/network-scripts/ifcfg-eth$i

if [ $? -ne 0 ];then

echo "can't cancel the UUID for $name"

exit

fi

((i++))

echo "$name modification completed"

done



echo "start modifying the grub file"

sed -i "s#rhgb#rhgb net.ifnames=0 biosdevname=0 #g" /etc/default/grub

if [ $? -ne 0 ];then

echo "can't alter the grub"

exit

fi

/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg

if [ $? -ne 0 ];then

echo "can't make the grub"

exit

else

echo "Everything's fine,pls reboot"

exit

fi

 

#执行脚本,显示成功自动重启

#sh chagename.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值