Linux網絡卡沒有eth0顯示ens33原因以及解決辦法
原因
首先說明下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 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
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 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 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 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