RHEL7/CentOS7中更改網卡默認名稱

一、重命名並修改網卡配置文件,將"NAME"參數更爲咱們熟悉的「eth*」,這裏我將其改成"eth0"linux

 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

二、修改grub文件/etc/sysconfig/grub,在「GRUB_CMDLINE_LINUX」參數行中添加「net.ifnames=0 biosdevname=0」ios

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"
三、從新生成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

四、重啓系統後,ifconfig查看:vim

 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
五、爲了雙重保險起見建議使用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
相關文章
相關標籤/搜索