在RHEL及CentOS 7上,由于systemd 和 udev 引入了一种新的网络设备命名方式 —— 一致网络设备命名(CONSISTENT NETWORK DEVICE NAMING),可以根据固件、拓扑、位置信息来设置固定名字,带来的好处是命名自动化,名字完全可预测,在硬件坏了以后更换也不会影响设备的命名,这样可以让硬件的更换无缝化,带来的不利是新的设备名称比传统的名称难以阅读。
[root@localhost network-scripts]# sed -i '/ONBOOT/s/no/yes/' ifcfg-eno*
[root@localhost network-scripts]# systemctl restart network
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@localhost ~] # ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1 /8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1 /128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:0d:25:d9 brd ff:ff:ff:ff:ff:ff
inet 192.168.199.131 /24 brd 192.168.199.255 scope global dynamic eno16777736
valid_lft 39693sec preferred_lft 39693sec
inet6 fe80::20c:29ff:fe0d:25d9 /64 scope link
valid_lft forever preferred_lft forever
|
修改步骤
1、修改grub2启动参数
编辑/etc/sysconfig/grub文件,在GRUB_CMDLINE_LINUX结尾的双引号前加上“net.ifnames=0 biosdevname=0”
[root@localhost ~]# 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="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet " GRUB_DISABLE_RECOVERY="true"
2、生成新的GRUB文件更新GRUB、内核配置
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
3、重命名网卡配置文件
[root@localhost ~]# mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0
注意:如果之前配置了固定IP,还需要将配置文件中的“NAME=eno16777736”改成“NAME=eth0”,如果是自动获取那就不用管了。
4、重启系统生效
[root@localhost ~]# ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:0d:25:d9 brd ff:ff:ff:ff:ff:ff inet 192.168.199.131/24 brd 192.168.199.255 scope global dynamic eth0 valid_lft 43189sec preferred_lft 43189sec inet6 fe80::20c:29ff:fe0d:25d9/64 scope link valid_lft forever preferred_lft forever
本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/2072729