Network config for KVM on physical machine with single NIC and single public IP

kvm-virtualization

I have a physical machine running CentOS 6.4 and I will rent a place to run it in a data center.
I want to install KVM on that machine to run some virtual machines.

The problem is my physical machine have only one NIC and the data center give me a public IP for that interface. So how should I configure network on the physical machine to make it assign for each vm a private IP that can connect to Internet.

If I create a br0 bridged with eth0 interface and create a vm with option --bridge=br0 then KVM could not assign an IP for the vm so setup can not be done.

Should I use NAT mode?
Does KVM have any host-only network like Virtualbox? But the vm still has to connect to outside?

Thank you!

Update

I install the guest network using NAT (--network network:default) and then I only have to port-forwarding from the host.

But if I config br0 bridged with physical eth0 then the guest can not get an IP from boot. So I removed the br0 and it worked.

Best Answer

If you use libvirt, all you need to do is change your VMs to use NAT mode. If you set your VMs to use the br0 bridge that has eth0 enslaved, and use that for your VM, you will not get an IP because your ISP's DHCP server does not have a lease record for your VM's MAC address. Using a bridge is like plugging your Internet uplink into a switch, and then plugging your physical machine and your VM each into the same switch with its own cable.

Libvirt will automatically setup the private NATed network via dnsmasq. You'll have to set that up manually if you aren't using libvirt, but I highly recommend using libvirt.