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

CentOS7修改網絡卡名稱

我在VMWare workstation裡面安裝的centos7虛擬機器設定了2張網絡卡,網絡卡名稱預設為eno16777736、eno33554984:

[root@controller ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:3a:78:ee brd ff:ff:ff:ff:ff:ff inet 192.168.128.85/24 brd 192.168.128.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80
::250:56ff:fe3a:78ee/64 scope link valid_lft forever preferred_lft forever 3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:72:41:10 brd ff:ff:ff:ff:ff:ff inet 10.10.10.10/24 brd 10.10.10.255 scope global eno33554984 valid_lft forever preferred_lft forever inet6 fe80
::20c:29ff:fe72:4110/64 scope link valid_lft forever preferred_lft forever

如果改為eth0、eth1,該如何操作呢?

1.修改配置

[root@controller ~]# vi /etc/default/grub

GRUB_CMDLINE_LINUX 加上 net.ifnames=0 biosdevname=0

GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"

2.重新載入配置
grub2-mkconfig -o /boot/grub2/grub.cfg

[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.5.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.5.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.28.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.28.3.el7.x86_64.img
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-0ff0e879cd2f443cb90ec9afa4d66dfb
Found initrd image: /boot/initramfs-0-rescue-0ff0e879cd2f443cb90ec9afa4d66dfb.img
done

3.修改網絡卡名稱

[root@controller ~]# cd /etc/sysconfig/network-scripts/
[root@controller network-scripts]# vi ifcfg-eno16777736

修改為
NAME=eth0
DEVICE=eth0

[root@controller network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0

同樣另外一張網絡卡改為eth1

4.重啟機器

發現通過ssh連線不到 192.168.128.85
進入vmware控制檯檢視,還是顯示原網絡卡名稱,再檢視網路服務狀態,顯示failed
這裡寫圖片描述

如何解決?

進入目錄 /etc/udev/rules.d/
[[email protected] ~]# cd /etc/udev/rules.d/
檢視 90-eno-pix.rules

# This file was automatically generated on systemd update
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"

看到還是之前的網絡卡名稱
刪掉此檔案,或者改為正確的網絡卡名稱,注意和mac對應,然後重啟機器

這次成功了

[root@controller ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:3a:78:ee brd ff:ff:ff:ff:ff:ff
    inet 192.168.128.85/24 brd 192.168.128.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe3a:78ee/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:72:41:10 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.10/24 brd 10.10.10.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe72:4110/64 scope link 
       valid_lft forever preferred_lft forever