[libvirt] how to assign an ip when assign a NIC or VF to the Virtual Machine?
Richard W.M. Jones
rjones at redhat.com
Sat May 7 16:55:06 UTC 2011
On Sat, May 07, 2011 at 11:24:23PM +0800, guan qin wrote:
> So how can I assign an ip to the VM when assign the NIC or VF to the
> VM
It doesn't work like this.
Just like with real hardware, all the virtual hardware has is a MAC
address. The (real or virtual) machine has to use some other method
to get an IP address and hostname after it has booted. As with real
machines, either it does that using DHCP, or it has the IP address
hard-coded somewhere on disk.
The best solution is to create a separate DHCP service which assigns a
specific IP address to the known MAC address of the NIC/VF. You can
get the MAC address using "virsh dumpxml".
Another solution would be to edit the guest before booting it and give
it the address you want it to have. eg for RHEL and Fedora guests:
guestfish -i -d MyGuest -- \
upload - /etc/sysconfig/network-scripts/ifcfg-eth0 <<_EOF
DEVICE=eth0
IPADDR=192.168.1.2
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
ONBOOT=yes
_EOF
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
More information about the libvir-list
mailing list