1. 程式人生 > >VM 克隆Linux虛擬機器網絡卡配置

VM 克隆Linux虛擬機器網絡卡配置

使用VM克隆Linux虛擬機器時,克隆的虛擬機器可能會發生網路障礙,ping不通外網,這是因為克隆的虛擬機器中的uuid和HWADDR和原虛擬機器一樣的,在區域網內有衝突。(本人使用的是NAT模式) 我們可以看到克隆機和原虛擬機器使用的是不同的網絡卡,克隆機使用的是"eth1",而原虛擬機器使用的是"eth0"; 克隆機的網絡卡

原虛擬機器的網絡卡

當我們配置靜態ip時會發現找不到"eth1"的配置檔案 在這裡插入圖片描述 那我們配置"eth0"網絡卡靜態ip重啟網路服務時,會發現重啟失敗,原因是找不到"eth0"網絡卡 找不到網絡卡 然後我們無論啟動"eth0"或"eth1"都不成功

[[email protected] ~]# ifup eth0
Error: No suitable device found: no device found for
connection 'System eth0'. [[email protected] ~]# ifup eth1 /sbin/ifup: configuration for eth1 not found. Usage: ifup <device name>

於是用"ifconfig"命令檢視網路介面引數發現,當前使用的是"eth1"介面 在這裡插入圖片描述

那麼,我們該怎麼做

檢視/etc/udev/rules.d/目錄下的70-persistent-net.rules,可以看到"eth0"的ATTR是原虛擬機器的MAC地址。我們將"eth0"的資訊刪掉再把"eth1"改成"eth0"。

[[email protected]
~]# vi /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)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ff:5e:6a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:18:cc:ea", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

然後去配置靜態ip,在配置靜態ip之前要做兩件事

  1. 生成新的UUID
[[email protected] ~]# uuidgen eth0
a70dfe6d-0a6c-4402-9c94-16e21b3c6e04
  1. 記下MAC地址 在這裡插入圖片描述

然後配置靜態ip,替換掉原來的UUID和HWADDR。

[[email protected] home]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0
HWADDR=00:0C:29:18:CC:EA
TYPE=Ethernet
UUID=a70dfe6d-0a6c-4402-9c94-16e21b3c6e04
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static

IPADDR=192.168.201.133
PREFIX=24
GATEWAY=192.168.201.2
DNS1=8.8.8.8

重啟網路服務成功

[[email protected] ~]# service network restart
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1
state: activating
state: activated
Connection activated
                                                           [  OK  ]

圖形介面中的網路圖示也改變了 在這裡插入圖片描述 網絡卡配置成功