[Linux系统] 如何修改CentOS7网卡名

一、关闭一致性网络设备命名法

cat /etc/sysconfig/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 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" GRUB_DISABLE_RECOVERY="true"

在GRUB_CMDLINE_LINUX中添加net.ifnames=0 biosdevname=0,文件内容变为如下:

cat /etc/sysconfig/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 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet" GRUB_DISABLE_RECOVERY="true"

更新Grub内核配置:

grub2-mkconfig -o /boot/grub2/grub.cfg

Generating grub configuration
file ... Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-f034e6e19df748b7a27fad77b06e3179 Found initrd image: /boot/initramfs-0-rescue-f034e6e19df748b7a27fad77b06e3179.img done

二、修改/etc/udev/rules.d/90-eno-fix.rules文件

如果文件不存在,则新建。

内容如下:

# This file was automatically generated on systemd update
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3e:89:a4", NAME="eno-16777xxx"

将Name修改为eth0:

# This file was automatically generated on systemd update
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3e:89:a4", NAME="eth0"

如果有多个网卡,则会存在多条记录:

# This file was automatically generated on systemd update
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3e:89:a4", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3e:89:a6", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3e:89:a8", NAME="eth2"

三、重启计算机

 

reboot

 

四、修改配置文件

将原本网卡的配置文件修改为新网卡名:

mv /etc/sysconfig/network-scripts/ifcfg-eno16777xxx /etc/sysconfig/network-scripts/ifcfg-eth0

然后修改配置文件:

TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth0"
#UUID="c1f4ef5b-92fb-4037-b8e5-2a252e57e32c"
DEVICE="eth0"
ONBOOT="yes"
IPADDR="192.168.1.180"
PREFIX="24"
GATEWAY="192.168.1.1"
DNS1="61.139.2.69"

五、关闭NetworkManager服务

systemctl stop NetworkManager
systemctl disable NetworkManager

六、重启网络服务

systemctl restart network

七、查看网络是否修改成功

[root@centos-base network-scripts]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.180  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe31:171  prefixlen 64  scopeid 0x20<link>
        inet6 240e:398:c0:ddc0:20c:29ff:fe31:171  prefixlen 64  scopeid 0x0<global>
        ether 00:0c:29:31:01:71  txqueuelen 1000  (Ethernet)
        RX packets 1091  bytes 73254 (71.5 KiB)
        RX errors 0  dropped 298  overruns 0  frame 0
        TX packets 217  bytes 44511 (43.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
posted @ 2019-10-15 13:34  风间悠香  阅读(1117)  评论(0编辑  收藏  举报