1. 程式人生 > >CentOS7 更改網絡卡名稱

CentOS7 更改網絡卡名稱

 

1.ifconfig檢視網絡卡名稱為ens33

複製程式碼
[[email protected] ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.2  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::20c:29ff:fe8b:bbbe  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:8b:bb:be  txqueuelen 1000  (Ethernet)
        RX packets 62  bytes 7151 (6.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 91  bytes 12163 (11.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 336  bytes 28600 (27.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 336  bytes 28600 (27.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.編輯網絡卡的配置檔案 vi /etc/sysconfig/network-scripts/ifcfg-ens33 將裡面的NAME和DEVICE項修改為eth0

 

複製程式碼
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.137.2
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
DNS1=114.114.114.114
DNS2=8.8.8.8
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0  #更改
UUID=972a1eb3-049f-4db2-80f5-7d8fd28ef76f
DEVICE=eth0 #更改
ONBOOT=yes

 

3.重新命名網絡卡配置檔案ifcfg-ens33為ifcfg-eth0

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# mv ifcfg-ens33 ifcfg-eth0

4.編輯/etc/default/grub並加入“net.ifnames=0 biosdevname=0 ”到GRUBCMDLINELINUX變數

 

[[email protected] network-scripts]# 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="crashkernel=auto net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"  

 

5.執行命令grub2-mkconfig -o /boot/grub2/grub.cfg 來重新生成GRUB配置並更新核心引數。

 

[[email protected] network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-b7f83ca165964a47b8b283907b126140
Found initrd image: /boot/initramfs-0-rescue-b7f83ca165964a47b8b283907b126140.img
done

6.重啟系統

[[email protected] network-scripts]# reboot

7.驗證

 

[[email protected] ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.2  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::e677:ea95:d090:ba39  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:8b:bb:be  txqueuelen 1000  (Ethernet)
        RX packets 104  bytes 13136 (12.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 107  bytes 12773 (12.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 72  bytes 6252 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6252 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0