原因
首先说明下eth0与ens33的关系:
目前的主流网卡为使用以太网络协定所开发出来的以太网卡 (Ethernet),因此我们 Linux 就称呼这种网络接口为 ethN (N 为数字)。 举例来说,主机上面有一张以太网卡,因此主机的网络接口就是 eth0 (第一张为 0 号开始)。新的 CentOS 7 开始对于网卡的编号有另一套规则,网卡的界面代号与网卡的来源有关,网卡名称会是这样分类的:
eno1 :代表由主板 BIOS 内置的网卡
ens1 :代表由主板 BIOS 内置的 PCI-E 界面的网卡
enp2s0 :代表 PCI-E 界面的独立网卡,可能有多个插孔,因此会有 s0, s1... 的编号~
eth0 :如果上述的名称都不适用,就回到原本的默认网卡编号
所以会有ens33这种网卡表现形式。
解决办法
1.编辑网卡的配置文件
vi /etc/sysconfig/network-scripts/ifcfg-ens33 将里面的NAME和DEVICE项修改为eth0,ONBOOT需修改为yes
[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=eth0 # 修改ens33为eth0
UUID=2171c1b0-0e2a-498c-9b9b-0071d6597fe0
DEVICE=eth0 # 修改ens33为eth0
ONBOOT=yes # 修改no为yes
2.重命名网卡配置文件
将ifcfg-ens33为ifcfg-eth0
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# mv ifcfg-ens33 ifcfg-eth0
3.编辑/etc/default/grub
加入“net.ifnames=0 biosdevname=0 ”到GRUBCMDLINELINUX变量
[root@localhost network-scripts]# vi /etc/default/grub
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 net.ifnames=0 biosdevname=0 spectre_v2=retpoline
rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"GRUB_DISABLE_RECOVERY="true"
4.重新生成GRUB配置并更新内核参数
运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数。
[root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1127.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ece52f273aa045ad8822b6197e4910d0
Found initrd image: /boot/initramfs-0-rescue-ece52f273aa045ad8822b6197e4910d0.img
done
5.重启系统
[root@localhost network-scripts]# reboot
6. 检验配置
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.182.130 netmask 255.255.255.0 broadcast 192.168.182.255
inet6 fe80::4347:403c:4dc4:2f0c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:18:b9:3f txqueuelen 1000 (Ethernet)
RX packets 60 bytes 6530 (6.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 76 bytes 11742 (11.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:41:2d:f8 txqueuelen 1000 (Ethernet)
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