当我们使用centos7时网卡名子过长,我们需要更改成自己想要的名字,过程如下:

1、备份并修改/etc/default/grub

[root@controller03 ~]# cp /etc/default/grub /etc/default/grub.bk

2、 let's disable the predictable naming rule. For that, you can pass "net.ifnames=0" kernel parameter during boot. This is achieved by editing /etc/default/grub and adding "net.ifnames=0" to GRUB_CMDLINE_LINUX variable

[root@controller03 ~]# cat  /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=root_vg01/lv_01 net.ifnames=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

3、run this command to regenerate GRUB configuration with updated kernel parameters

[root@controller03 ~]# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bk
[root@controller03 ~]# sudo grub2-mkconfig -o /boot/grub2/grub.cfg

4、修改 vim  /etc/udev/rules.d/70-persistent-net.rules 根据MAC对应 自己想要定义的网卡的名字

[root@controller03 ~]# cat  /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",ATTR{address}=="52:54:00:57:1a:ef", ATTR{type}=="1", KERNEL=="eth*",NAME="ens4"

#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",ATTR{address}=="52:54:00:37:dc:e0", ATTR{type}=="1", KERNEL=="eth*",NAME="eth1"

5、最后重启系统即可!


参考链接

http://ask.xmodulo.com/change-network-interface-name-centos7.html