一、已经装好系统CentOS7修改网卡为eth0
1. 修改网卡配置文件 [root@localhost ~]# mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0 [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 NAME=eth0 2. GRUB添加kernel参数 # vim /etc/sysconfig/grub GRUB_CMDLINE_LINUX="...... net.ifnames=0" 3.重新装载配置文件 # grub2-mkconfig -o /boot/grub2/grub.cfg 4. reboot
二、未装好系统CentOS7修改网卡为eth0
也可在安装系统时添加kernel参数 net.ifnames=0
三、修改网卡名脚本
#!/bin/sh a=`ifconfig |grep mtu |cut -f1 -d ':'` b=0 for i in $a do if [ $i != 'lo' ] then echo -e " 33[40;32m ===================================start edit eth$b================================================================================ 33[0m" sed -i "s/^NAME.*$/NAME=eth${b}/g" /etc/sysconfig/network-scripts/ifcfg-$i sed -i "s/^BOOTPROTO.*$/BOOTPROTO=static/g" /etc/sysconfig/network-scripts/ifcfg-$i sed -i "s/^DEVICE.*$/DEVICE=eth${b}/g" /etc/sysconfig/network-scripts/ifcfg-$i sed -i '/PROXY_METHO|BROWSER_ONLY|DEFROUTE|IPV4_FAILURE_FATAL|IPV6*|UUID/d' /etc/sysconfig/network-scripts/ifcfg-$i mv /etc/sysconfig/network-scripts/ifcfg-$i /etc/sysconfig/network-scripts/ifcfg-eth$b ((b++)) sleep 2 else echo "skip $i" fi done sed -i 's/rhgb/net.ifnames=0 biosdevname=0 &/' /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg echo -e " 33[40;32m ===================================edit network finish=========================================================================== 33[0m"