概述
我們使用Linux系統,網卡名稱通常都是eth0,但是有一些新的linux發行版,網卡名字 enps33 或 enp0s25。
peng@ubuntu:~$ ifconfig
ens33 Link encap:Ethernet HWaddr 00:0c:29:fd:4d:3a
inet addr:192.168.0.113 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::6abf:1256:56f4:c740/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2032 errors:0 dropped:0 overruns:0 frame:0
TX packets:1381 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2348705 (2.3 MB) TX bytes:111240 (111.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:256 errors:0 dropped:0 overruns:0 frame:0
TX packets:256 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20758 (20.7 KB) TX bytes:20758 (20.7 KB)
Eth0和ens的差別
- eno1:代表由主辦bios内置的網卡
- Ens:代表有主機闆bios内置的PCI-E網卡
- Enp2s0:PCI-E獨立網卡
- Eth0:如果以上都不使用回到預設的網卡名
網卡名稱字元含義
- 1、前2個字元的含義
- en 以太網 Ethernet
- wl 無線區域網路 WLAN
- ww 無線廣域網 WWAN
- 2、第3個字元根據裝置類型選擇
o<index> on-board device index number
s<slot> hotplug slot index number
x<MAC> MAC address
p<bus>s<slot> PCI geographical location
p<bus>s<slot> USB port number chain
這主要是由于 systemd,大多數較新的發行版linux的NIC采用非标準名稱命名。 這給很多人帶來了不友善,尤其是那些運維伺服器的人。 這意味着他們之前編寫的很多配置檔案都需要修改。
解決方法
下面教大家一個方法,隻需幾秒鐘就可以解決這個問題,它适用于幾乎所有 Linux 作業系統: Ubuntu、Linux Mint、CentOS、RHEL/Fedora、Debian等...、
第一步
使用管理者權限/etc/default/grub檔案
peng@ubuntu:~$ sudo vim /etc/default/grub
增加以下配置資訊:
14 GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
- ubuntu修改截圖如下:
- CentOS 8 的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 resume=UUID=bbed66de -8c71-44e3-aa82-da7830ccc98e net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
第二步:更新GRUB
- 對于 Debian 的 Ubuntu/Mint:
sudo update-grub
- Centos/RHEL
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
操作如下:
peng@ubuntu:~$ update-grub
grub-mkconfig: You must run this as root
peng@ubuntu:~$ sudo update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.15.0-142-generic
Found initrd image: /boot/initrd.img-4.15.0-142-generic
Found linux image: /boot/vmlinuz-4.15.0-140-generic
Found initrd image: /boot/initrd.img-4.15.0-140-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
第三步,重新開機系統
重新開機系統後,就可以看到網卡名字變成了eth0
快來試一下吧!