KVM克隆虚拟机后,需要设置虚拟机的网络,进入虚拟机后会发现没有eth0网卡,是因为虚拟机还使用原来的mac地址,需要修改之。
编辑/etc/udev/rules.d/70-persistent-net.rules文件,把NAME="eth0"的那行配置注释掉或者删掉,把NAME="eth1"的修改成NAME="eth0",修改后如下:
# 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 0x1af4:0x1000 (virtio-pci)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:56:28:68", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:12:41:cd", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
更改网卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0,将HWADDR的值修改为/etc/udev/rules.d/70-persistent-net.rules文件中的新值,修改后如下:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="none"
HWADDR="52:54:00:12:41:cd"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="49d231f8-c5c4-40cd-8ebb-2c0b2d7a7864"
IPADDR="172.16.101.12"
PREFIX="16"
GATEWAY="172.16.0.254"
DNS1="172.20.1.4"
DNS2="180.76.76.76"
重启系统。
注意:在克隆虚拟机时,好像virbr0会对虚拟机的网络有影响(我在没有关闭virbr0之前网络设置不成功,具体原因未知),可能需要关闭virbr0:
# virsh net-list
# virsh net-destroy default
# virsh net-undefine default
# service libvirtd restart