某些情况下需要多台服务器网卡名称保持一致,使用此脚本修改网卡名为传统显示方式,建议在系统安装后立即进行,使用前请自行测试
安装系统时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