网络设备的名称从 eth0 开始排序, 使用 vmware 创建网络的时候, 网络设备的名称缺省的被设定为了 eno16777736, 使用 ip addr 或者 ifconfig 确认的时候, 我们看到的是 eno16777736 而不是 eth0, 本来这不是什么事, 但是使用诸如 DCOS 或者 kubernetes1.4 等的时候, 有些版本对这个还是有些介意的, 本文将简单介绍一下如何在 centos7 下改变网络设备名称.
事前确认
CentOS 和 Linux 内核版本
- [root@host31 ~]# uname -a
- Linux host31 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
- [root@host31 ~]#
- 1
- 2
- 3
缺省的网络设备名称
- [root@host31 ~]# ifconfig
- eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- .NET 192.168.32.131 netmask 255.255.255.0 broadcast 192.168.32.255
- inet6 fe80::20c:29ff:fe3e:8b29 prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:3e:8b:29 txqueuelen 1000 (Ethernet)
- RX packets 11736 bytes 15663740 (14.9 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 4502 bytes 311217 (303.9 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- .NET 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 0 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- [root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
ifconfig 在 centos7 上已经不再是确认工具, 因为 net-tools 已经被 ip 工具所代替, 我们将会在别的文章中进行介绍, 对于不熟悉或者不想熟悉 ip 命令的, 目前仍然可以使用 yum install.NET-tools 来解决这个问题.
grub 文件修正
修正 / etc/sysconfig/grub 文件, 在 GRUB_CMDLINE_LINUX 的末尾追加 net.ifnames=0 biosdevname=0
- [root@host31 ~]# cp /etc/sysconfig/grub /etc/sysconfig/grub.bak
- [root@host31 ~]# vi /etc/sysconfig/grub
- [root@host31 ~]# diff /etc/sysconfig/grub /etc/sysconfig/grub.bak
- 6c6
- <GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
- ---
- > GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
- [root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
执行 grub2-mkconfig
执行命令: grub2-mkconfig -o /boot/grub2/grub.cfg
- [root@host31 ~]# 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-54b1ac274dec4980aa1a41f4a54a3245
- Found initrd image: /boot/initramfs-0-rescue-54b1ac274dec4980aa1a41f4a54a3245.img
- done
- [root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
生成 ifcfg-eth0 文件
修正对象文件
- [root@host31 ~]# cd /etc/sysconfig/network-scripts
- [root@host31 network-scripts]# ls *eno*
- ifcfg-eno16777736
- [root@host31 network-scripts]# ls *eth0*
- ls: cannot access *eth0*: No such file or directory
- [root@host31 network-scripts]# cat ifcfg-eno16777736
- TYPE="Ethernet"
- BOOTPROTO="none"
- DEFROUTE="yes"
- IPV4_FAILURE_FATAL="no"
- IPV6INIT="yes"
- IPV6_AUTOCONF="yes"
- IPV6_DEFROUTE="yes"
- IPV6_FAILURE_FATAL="no"
- NAME="eno16777736"
- UUID="dbcb97e7-da55-42f4-b3af-ed4e909320ba"
- DEVICE="eno16777736"
- ONBOOT="yes"
- IPADDR="192.168.32.131"
- PREFIX="24"
- GATEWAY="192.168.32.2"
- DNS1="8.8.8.8"
- DNS2="8.8.4.4"
- IPV6_PEERDNS="yes"
- IPV6_PEERROUTES="yes"
- IPV6_PRIVACY="no"
- [root@host31 network-scripts]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
修正 NAME 和 DEVICE 两个项目
- [root@host31 network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0
- [root@host31 network-scripts]# vi ifcfg-eth0
- [root@host31 network-scripts]# cat ifcfg-eth0
- TYPE="Ethernet"
- BOOTPROTO="none"
- DEFROUTE="yes"
- IPV4_FAILURE_FATAL="no"
- IPV6INIT="yes"
- IPV6_AUTOCONF="yes"
- IPV6_DEFROUTE="yes"
- IPV6_FAILURE_FATAL="no"
- NAME="eth0"
- UUID="dbcb97e7-da55-42f4-b3af-ed4e909320ba"
- DEVICE="eth0"
- ONBOOT="yes"
- IPADDR="192.168.32.131"
- PREFIX="24"
- GATEWAY="192.168.32.2"
- DNS1="8.8.8.8"
- DNS2="8.8.4.4"
- IPV6_PEERDNS="yes"
- IPV6_PEERROUTES="yes"
- IPV6_PRIVACY="no"
- [root@host31 network-scripts]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
重启
命令: reboot
再确认
命令: ifconfig 或者 ip addr
- [root@host31 ~]# ifconfig
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- .NET 192.168.32.131 netmask 255.255.255.0 broadcast 192.168.32.255
- inet6 fe80::20c:29ff:fe3e:8b29 prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:3e:8b:29 txqueuelen 1000 (Ethernet)
- RX packets 40 bytes 5727 (5.5 KiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 53 bytes 9326 (9.1 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- .NET 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 0 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- [root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
可以确认在重启之后, 网络设备名称已经从 eno16777736 变成 eth0 了.
来源: http://www.bubuko.com/infodetail-2911735.html