首页 > 代码库 > CentOS7 更改网卡名称

CentOS7 更改网卡名称

1.ifconfig查看网卡名称为ens33

[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.2  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::20c:29ff:fe8b:bbbe  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:8b:bb:be  txqueuelen 1000  (Ethernet)
        RX packets 62  bytes 7151 (6.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 91  bytes 12163 (11.8 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 1  (Local Loopback)
        RX packets 336  bytes 28600 (27.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 336  bytes 28600 (27.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.编辑网卡的配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens33 将里面的NAME和DEVICE项修改为eth0

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.137.2
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
DNS1=114.114.114.114
DNS2=8.8.8.8
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=972a1eb3-049f-4db2-80f5-7d8fd28ef76f
DEVICE=eth0
ONBOOT=yes

3.重命名网卡配置文件ifcfg-ens33为ifcfg-eth0

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# mv ifcfg-ens33 ifcfg-eth0

4.编辑/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 rhgb quiet" GRUB_DISABLE_RECOVERY="true"

5.运行命令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-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-b7f83ca165964a47b8b283907b126140
Found initrd image: /boot/initramfs-0-rescue-b7f83ca165964a47b8b283907b126140.img
done

6.重启系统

[root@localhost network-scripts]# reboot

7.验证

[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.2  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::e677:ea95:d090:ba39  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:8b:bb:be  txqueuelen 1000  (Ethernet)
        RX packets 104  bytes 13136 (12.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 107  bytes 12773 (12.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 1  (Local Loopback)
        RX packets 72  bytes 6252 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6252 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

CentOS7 更改网卡名称