centos7下網絡設備名稱修改方法
阿新 • • 發佈:2019-01-07
collision ifconf sys tty com pre ima scu comment
網絡設備的名稱從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
inet 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
inet 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
inet 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
inet 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了。
再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://www.cnblogs.com/captainbed
centos7下網絡設備名稱修改方法