1. 程式人生 > >解決拷貝的虛擬機網卡配置不正確的問題

解決拷貝的虛擬機網卡配置不正確的問題

說明 網絡連接 name lin work prot system onf 啟動

解決拷貝的虛擬機網卡配置不正確的問題

一、背景

在開發的過程中,我們經常會拷貝虛擬機。有時候我們拷貝來的虛擬機的網卡不能正常啟動。出現“沒有找到合適的設備:沒有找到可擁有鏈接System eth0的設備”。

二、解決問題

我的虛擬機的網絡適配器的網絡連接模式是橋接模式。

a、清空 /etc/udev/rules.d/70-persistent-net.rules 文件。

b、重啟機器。(可使用reboot命令重啟機器)。重啟後的系統裏的 /etc/udev/rules.d/70-persistent-net.rules會生成新的網卡MAC地址等網卡信息。

c、配置網卡文件ifcfg-eth(0-n)。如果有多個網卡,系統/etc/sysconfig/network-scripts路徑下有多個以ifcfg-eth開頭的文件。我們系統就一個網卡,所以配置ifcfg-eth0文件即可。配置信息如下:

70-persistent-net.rules信息如下:

[root@localhost ~]# cat /etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
# You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100f (e1000)
# PCI device 0x8086:0x100f (e1000)
# PCI device 0x8086:0x100f (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:65:ce:1f", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

ifcfg-eth0的信息如下:

DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0c:29:65:ce:1f
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.120
GATEWAY=192.168.1.1
TYPE=Ethernet

說明:把70-persistent-net.rules 文件中ATTR{address} 和 ifcfg-eth0中的HWADDR的值配置成一樣,70-persistent-net.rules文件中的NAME和ifcfg-eth0的DEVICE的值配置成一樣。最後重啟機器就可以了。

解決拷貝的虛擬機網卡配置不正確的問題