虛擬機改名方法
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736裏面的name和device,並把配置文件名改為ifcfg-eth0。重啟網絡:systemctl restart network.service。後來因重啟失敗還原為原來的信息,以為會正常,但仍沒有解決。
# systemctl restart network.service
Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
根據提示查看網卡信息
# systemctl status network.service
查看日誌
# cat /var/log/messages |grep network
Jul 4 10:05:10 dg-p systemd: Starting LSB: Bring up/down networking...
Jul 4 10:05:10 dg-p network: Bringing up loopback interface: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
Jul 4 10:05:10 dg-p network: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
Jul 4 10:05:10 dg-p network: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
Jul 4 10:05:10 dg-p network: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
Jul 4 10:05:10 dg-p network: [ OK ]
Jul 4 10:05:11 dg-p network: Bringing up interface eno16777736: Error: Connection activation failed: No suitable device found for this connection.
Jul 4 10:05:11 dg-p network: [FAILED]
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p network: RTNETLINK answers: File exists
Jul 4 10:05:11 dg-p systemd: network.service: control process exited, code=exited status=1
Jul 4 10:05:11 dg-p systemd: Failed to start LSB: Bring up/down networking.
Jul 4 10:05:11 dg-p systemd: Unit network.service entered failed state.
Jul 4 10:05:11 dg-p systemd: network.service failed.
解決:
百度後很多說是MAC地址或者NetworkManager服務的問題,試過後仍未解決。解鈴還須系鈴人,試著修改網卡名---
(1)修改網卡名和配置文件
# mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0
修改配置文件裏面name和device
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
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
NAME=eth0
UUID=d890d6e6-01f6-4063-bf70-cd4e1787d0a8
HWADDR=00:50:56:8b:57:82 #這裏原文件沒有,手動添加上去
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.70.42
NETMASK=255.255.255.0
GATEWAY=192.168.70.254
(2)修改/etc/sysconfig/grub,添加net.ifnames=0 biosdevname=0
# vi /etc/sysconfig/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=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
(3)手動生成70-persistent-net.rules以及其他方法
查看接口的MAC地址
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:28:ac:54 brd ff:ff:ff:ff:ff:ff
生成文件
# vi /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:28:ac:54", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
或
#grub2-mkconfig -o /boot/grub2/grub.cfg #這個沒有試過,有興趣的可以自己試試
重啟機器:
# reboot
虛擬機改名方法