查看当前系统版本
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
查看当前网卡信息
[root@localhost ~]# ifconfig | head -2
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255
可以看到网卡名为ens33。
为了方便管理和使用改为以“eth”开头的网卡名。
修改配置文件
- 修改前
[root@localhost ~]# cat -n /etc/default/grub
1 GRUB_TIMEOUT=5
2 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
3 GRUB_DEFAULT=saved
4 GRUB_DISABLE_SUBMENU=true
5 GRUB_TERMINAL_OUTPUT="console"
6 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
7 GRUB_DISABLE_RECOVERY="true"
-
修改后
在第六行的末尾添加 net.ifnames=0 biosdevname=0
[root@localhost ~]# cat -n /etc/default/grub
1 GRUB_TIMEOUT=5
2 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
3 GRUB_DEFAULT=saved
4 GRUB_DISABLE_SUBMENU=true
5 GRUB_TERMINAL_OUTPUT="console"
6 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
7 GRUB_DISABLE_RECOVERY="true"
- 重新生成grub,然后重启
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
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-e7698cd933f74608881ae839d102df88
Found initrd image: /boot/initramfs-0-rescue-e7698cd933f74608881ae839d102df88.img
done
修改网卡名称
[root@localhost ~]# nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 1 f8dd63e3-2724-3dc4-b0c4-03976af2a979 ethernet eth0
ens33 8c191747-33ba-449b-b52a-04c0627281ab ethernet --
[root@localhost ~]# nmcli connection delete ens33 //删除原有的错误网卡
[root@localhost ~]# nmcli connection delete Wired\ connection\ 1
[root@localhost ~]# nmcli connection show
[root@localhost ~]# nmcli connection add type ethernet ifname eth0 con-name eth0
[root@localhost ~]# nmcli connection show
[root@localhost ~]# nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.1.200/24 autoconnect yes
[root@localhost ~]# nmcli connection up eth0
[root@localhost ~]# ifconfig |head -2
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255