实验环境:

操作系统:CentOS Linux release 7.5.1804 (Core)

虚拟机:VMware 10.0.1 

1.先编辑网卡的配置文件将里面的NAME DEVICE项修改为eth0

[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 

TYPE="Ethernet"

PROXY_METHOD="none"

BROWSER_ONLY="no"

BOOTPROTO="dhcp"

DEFROUTE="yes"

IPV4_FAILURE_FATAL="no"

IPV6INIT="yes"

IPV6_AUTOCONF="yes"

IPV6_DEFROUTE="yes"

IPV6_FAILURE_FATAL="no"

IPV6_ADDR_GEN_MODE="stable-privacy"

NAME="ens33"

UUID="9f75af90-bd5d-467e-b433-216456e4a49e"

DEVICE="ens33" #修改成DEVICE="eth0"

ONBOOT="yes"

2.重命名该配置文件。

[root@localhost network-scripts]# mv ifcfg-ens33  ifcfg-eth0

3.过编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0 ”到GRUB_CMDLINE_LINUX变量来实现

GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT="console"

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"  net.ifname=0 biosdevname=0

GRUB_DISABLE_RECOVERY="true"

4.运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数。

[root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg

/etc/default/grub:行6: net.ifnames=0: 未找到命令

原因:加入的代码放到双引号内

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet  net.ifname=0 biosdevname=0

[root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-3.10.0-862.9.1.el7.x86_64

Found initrd image: /boot/initramfs-3.10.0-862.9.1.el7.x86_64.img

Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64

Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img

Found linux image: /boot/vmlinuz-0-rescue-6c938bf5dc5b492088dafb0e745f01ec

Found initrd image: /boot/initramfs-0-rescue-6c938bf5dc5b492088dafb0e745f01ec.img

done

5.重启服务器

#shutdown -r now

检验效果:

[sky9890@localhost ~]$ ifconfig

eth0: flags=4163  mtu 1500

        inet 192.168.153.128  netmask 255.255.255.0  broadcast 192.168.153.255

        inet6 fe80::d84f:63df:d5a:2641  prefixlen 64  scopeid 0x20

        ether 00:0c:29:65:85:ee  txqueuelen 1000  (Ethernet)

        RX packets 90  bytes 10239 (9.9 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 97  bytes 12135 (11.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10

        loop  txqueuelen 1000  (Local Loopback)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0