RHEL7/CentOS7中更改网卡默认名称

1、重命名并修改网卡配置文件,将"NAME"参数更为我们熟悉的“eth*”,这里我将其改为"eth0"

 1 [root@localhost ~]# cd /etc/sysconfig/network-scripts/
 2 [root@localhost network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0
 3 [root@localhost network-scripts]# vim ifcfg-eth0
 4 HWADDR=00:0C:29:BA:53:E3
 5 TYPE=Ethernet
 6 BOOTPROTO=dhcp
 7 DEFROUTE=yes
 8 PEERDNS=yes
 9 PEERROUTES=yes
10 IPV4_FAILURE_FATAL=no
11 IPV6INIT=yes
12 IPV6_AUTOCONF=yes
13 IPV6_DEFROUTE=yes
14 IPV6_PEERDNS=yes
15 IPV6_PEERROUTES=yes
16 IPV6_FAILURE_FATAL=no
17 NAME=eth0    #修改此参数,和文件名称ifcfg-eth0保持一致
18 UUID=a937a6e4-f70d-4422-b617-ea0b53cab76e
19 ONBOOT=yes

2、修改grub文件/etc/sysconfig/grub,在“GRUB_CMDLINE_LINUX”参数行中添加“net.ifnames=0 biosdevname=0”

1 [root@localhost network-scripts]# vim /etc/sysconfig/grub 
2 GRUB_TIMEOUT=5
3 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
4 GRUB_DEFAULT=saved
5 GRUB_DISABLE_SUBMENU=true
6 GRUB_TERMINAL_OUTPUT="console"
7 GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/root vconsole.keymap=us vconsole.font=latarcyrheb-sun16 crashkernel=auto net.ifnames=0 biosdevname=0 rhgb quiet"
8 GRUB_DISABLE_RECOVERY="true"
3、重新生成grub配置并更新内核参数:
运行命令:”grub2-mkconfig -o /boot/grub2/grub.cfg“
1 [root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfgGenerating grub configuration file ...
2 Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
3 Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
4 Found linux image: /boot/vmlinuz-0-rescue-e5dec78a32184af9be1ffa5acfa5efbb
5 Found initrd image: /boot/initramfs-0-rescue-e5dec78a32184af9be1ffa5acfa5efbb.img
6 done

4、重启系统后,ifconfig查看:

 1 [root@localhost ~]# ifconfig
 2 eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
 3         ether 00:0c:29:ba:53:e3  txqueuelen 1000  (Ethernet)
 4         RX packets 480  bytes 48151 (47.0 KiB)
 5         RX errors 0  dropped 0  overruns 0  frame 0
 6         TX packets 0  bytes 0 (0.0 B)
 7         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 8 
 9 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
10         ether 00:0c:29:ba:53:ed  txqueuelen 1000  (Ethernet)
11         RX packets 28067  bytes 1904426 (1.8 MiB)
12         RX errors 0  dropped 0  overruns 0  frame 0
13         TX packets 0  bytes 0 (0.0 B)
14         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
5、为了双重保险起见建议使用udev规则管理,在”/etc/udev/rules.d“目录中创建一个网卡规则”70-net.rules“,并写入下面的语句:
ACTION=="add",SUBSYSTEM=="net",DRIVERS=="*",ATTR{address}=="00:0c:29:ba:53:e3",ATTR{type}=="1",KERNEL=="eth*",NAME="eth0"
1 [root@localhost ~]# cd /etc/udev/rules.d/
2 [root@localhost rules.d]# vim 70-net.rules
3 ACTION=="add",SUBSYSTEM=="net",DRIVERS=="*",ATTR{address}=="00:0c:29:ba:53:e3",ATTR{type}=="1",KERNEL=="eth*",NAME="eth0"
4 [root@localhost rules.d]# udevadm trigger

 

posted @ 2016-03-03 11:07  darren_lee  阅读(1110)  评论(0编辑  收藏  举报