Centos重启系统后网卡名称变更解决方法

  • 2019-03-11
  • 90

1、查看Centos7系统默认的网卡配置(eno16777736)

[root@server ~]# ifconfigeno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #系统默认的网卡名称
inet 172.16.0.2 netmask 255.255.0.0 broadcast 172.16.255.255inet6 fe80::20c:29ff:fefa:dbfa prefixlen 64 scopeid 0x20<link>ether 00:0c:29:fa:db:fa txqueuelen 1000 (Ethernet)RX packets 6699 bytes 8261881 (7.8 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 3006 bytes 215704 (210.6 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 0 (Local Loopback)RX packets 25200 bytes 1468912 (1.4 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 25200 bytes 1468912 (1.4 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@server ~]#

2、编辑centos7系统默认的网卡配置文件,将NAME、DEVICE选项修改为eth0

[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

TYPE=Ethernet

BOOTPROTO=none

TYPE=Ethernet

BOOTPROTO=none

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=eno16777736 此处修改为#NAME=eth0

UUID=68062773-e078-4f64-8df6-3cbdf4730a4b

DEVICE=eno16777736 此处修改为#DEVICE=eth0

ONBOOT=yes

DNS1=192.168.1.1

DNS2=114.114.114.114

IPADDR=172.16.0.2

PREFIX=16

IPADDR1=172.16.0.4

PREFIX1=16

IPADDR2=172.16.0.5

PREFIX2=16

GATEWAY=172.16.0.1

3、将Centos7系统网卡配置文件ifcfg-eno16777736重命名为ifcfg-eth0

[root@server ~]# mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0

4、更改/etc/default/grub启动菜单传递给内核的参数,在GRUB_CMDLINE_LINUX变量中加入“net.ifnames=0 biosdevname=0”

[root@server ~]# ls -ld /etc/sysconfig/grub

lrwxrwxrwx. 1 root root 17 Aug 26 2017 /etc/sysconfig/grub -> /etc/default/grub

[root@server ~]# 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_CMDLINE_LINUX变量net.ifnames=0 biosdevname=0

GRUB_DISABLE_RECOVERY="true"

5、运行grub2-mkconfig -o /boot/grub2/grub.cfg命令重新生成grub菜单并更新内核参数

[root@server ~]# 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-f818c03720a04698929d06982f96d567

Found initrd image: /boot/initramfs-0-rescue-f818c03720a04698929d06982f96d567.img

done

6、修改/etc/udev/rules.d/90-eno-fix.rules配置文件,将NAME=” eno16777736″修改为NAME=”eth0″

[root@server ~]# cat /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:fa:db:fa", NAME=" eno16777736"

[root@server ~]# sed -i 's#NAME="eno16777736"#NAME="eth0"#g' /etc/udev/rules.d/90-eno-fix.rules

[root@server ~]# cat /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:fa:db:fa", NAME="eth0" #修改NAME变量为eth0

7、重启Centos7系统,完成网卡改名

[root@server ~]# reboot

8、验证Centos7系统网卡改名的结果

[root@server ~]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #查看系统网卡名称已经设置为eth0

inet 172.16.0.2 netmask 255.255.0.0 broadcast 172.16.255.255

inet6 fe80::20c:29ff:fefa:dbfa prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:fa:db:fa txqueuelen 1000 (Ethernet)

RX packets 339 bytes 28141 (27.4 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 190 bytes 25047 (24.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 0 (Local Loopback)

RX packets 8034 bytes 469008 (458.0 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 8034 bytes 469008 (458.0 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@server ~]#

二、Centos7 系统安装开始时更改网卡名称方法

1、将光标移动到选择”Install CentOS 7”

https://images2018.cnblogs.com/blog/1405152/201805/1405152-20180525203503579-283553017.png

2、选择Tab键,打开Kernel启动项,再后面添加net.ifnames=0 biosdevname=0

https://images2018.cnblogs.com/blog/1405152/201805/1405152-20180525203515488-824737220.png

3、按Enter键,进入安装操作系统

https://images2018.cnblogs.com/blog/1405152/201805/1405152-20180525203415054-665167085.png

4、启动操作系统后,查看系统网卡名称

[root@localhost ~]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 172.16.0.2 netmask 255.255.0.0 broadcast 172.16.255.255

inet6 fe80::20c:29ff:fefa:dbfa prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:fa:db:fa txqueuelen 1000 (Ethernet)

RX packets 30 bytes 3660 (3.5 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 22 bytes 2078 (2.0 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 172.16.0.101 netmask 255.255.255.0 broadcast 172.16.0.255

inet6 fe80::20c:29ff:fefa:db04 prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:fa:db:04 txqueuelen 1000 (Ethernet)

RX packets 204 bytes 18958 (18.5 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 140 bytes 20300 (19.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 0 (Local Loopback)

RX packets 387 bytes 22683 (22.1 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 387 bytes 22683 (22.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@localhost ~]#

本文转载自:https://www.cnblogs.com/Wolf-Dreams/p/9090577.html