Centos7修改网卡名称

一、 原因

之前使用centos6,网卡名称是以eth命名的,突然centos7网卡变成eno********,很是不习惯。所以想把网卡名称改为eth的格式。

二、 修改名称

1、禁用该可预测命名规则。对于这一点,你可以在启动时传递“net.ifnames=0 biosdevname=0 ”的内核参数。这是通过编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0

”到GRUBCMDLINELINUX变量来实现的。

[root@cxm-slave ~]# vim /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 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
2、运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数。
[root@cxm-slave ~]# 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-f941d8c76f664780aaa0670fcb7e171a
Found initrd image: /boot/initramfs-0-rescue-f941d8c76f664780aaa0670fcb7e171a.img
done
3、编辑网卡配置文件
[root@cxm-slave network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0
[root@cxm-slave network-scripts]# vim ifcfg-eth0
NAME=eth0       ##修改内容
DEVICE=eth0
4、重启服务器验证
[root@cxm-slave network-scripts]# reboot
[root@cxm-slave ~]# ip a
1: lo:  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:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c6:c7:b8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.50/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 7184sec preferred_lft 7184sec
    inet 192.168.1.179/24 brd 192.168.1.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fec6:c7b8/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c6:c7:c2 brd ff:ff:ff:ff:ff:ff
    inet 11.11.11.22/24 brd 11.11.11.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fec6:c7c2/64 scope link 
       valid_lft forever preferred_lft forever

修改成功

三、 问题

如果没有成功,查看一下文件

[root@cxm-slave ~]# cat /etc/udev/rules.d/70-persistent-ipoib.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:3a:78:ee", NAME="eno16777736"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:72:41:10", NAME="eno33554984"

如果有内容就把eno****改成你想要的主机名

你可能感兴趣的:(Centos7修改网卡名称)