shell脚本自动修改centos7网卡名称
centos7的网卡名字默认是eno跟数字(如eno16780032),看着太不爽了,我习惯用eth0接口,故想用脚本自动修改,脚本修改网卡名后会自动重启系统生效.
脚本内容:
#!/bin/bash # function RENMAE_NIC() { local _NICNAME=$(ip addr | grep "^2"|awk -F ": " '{print $2}') if [[ ${_NICNAME} != "eth0" ]];then echo -e "\e[40;31m The nic name is [\e[40;31m${_NICNAME}\e[40;31m].\n\e[0m Rename nic name to 'eth0'.\e[0m" sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-${_NICNAME} sed -i s/"^NAME=.*$"/"NAME=eth0"/g /etc/sysconfig/network-scripts/ifcfg-${_NICNAME} sed -i s/"^DEVICE=.*$"/"DEVICE=eth0"/g /etc/sysconfig/network-scripts/ifcfg-${_NICNAME} sed -i '/IPV6/d' /etc/sysconfig/network-scripts/ifcfg-${_NICNAME} mv /etc/sysconfig/network-scripts/ifcfg-${_NICNAME} /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i s/'rhgb quiet"$'/'net.ifnames=0 biosdevname=0 rhgb quiet"'/g /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg echo -e "\e[32m The nic name has renamed.\n Rstart Now.\e[0m" reboot fi unset local _NICNAME } RENMAE_NIC
ps:
根据这篇文章进行了下小修改
https://github.com/guileliao/document/wiki/CentOS7系统安装完毕修改网卡名为eth0
评论: