Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks for your explain. I used to setup a NAT and a private host-only interface for vm in VirtualBox but I've never ever use that on KVM. So each vm will have an IP like 10.0.x.x? Should I connect the vms by those IP. Because on VBox I see all of them are 10.0.2.15. If ok,then I have to manually config iptables to port-forwarding to connect to each vm from outside? –  neo0 Nov 7 '13 at 1:58
    
Yes, you will have to manually configure iptables to forward because your ISP is only giving you one public IP. By default KVM uses 192.168.122.0/24 for NAT, but it works teh same as 10.0.x.x on VBox. –  Cocoabean Feb 3 at 23:02
add comment

I had your same problem with my hypervisor and I've managed it this way:

I've created a bridge br0 with the ip address:

DEVICE="br0"<br>
BOOTPROTO="none"<br>
HWADDR="XX:XX:XX:XX:XX:XX"<br>
NM_CONTROLLED="no"<br>
ONBOOT="yes"<br>
TYPE="Bridge"<br>
NETMASK="255.255.255.0"<br>
IPADDR="XXX.XXX.XXX.XXX"<br>
GATEWAY="XXX.XXX.XXX.XXX"<br>
DEFROUTE=yes<br>

I've configured eth0 this way:

DEVICE="eth0"<br>
BOOTPROTO="none"<br>
HWADDR="XX:XX:XX:XX:XX:XX"<br>
NM_CONTROLLED="no"<br>
ONBOOT="yes"<br>
TYPE="Ethernet"<br>
BRIDGE=br0<br>

The interface of each vm is a bridge on br0:

<interface type='bridge'>
  <mac address='YY:YY:YY:YY:YY:YY'/>
  <source bridge='br0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
share|improve this answer
    
I did bridge mode on my local machine and this type of config worked. But the problem is the Data center only give me a single public IP, there is no DHCP. Then the vm did not get an IP to install. Think I have to use NAT mode. –  neo0 Nov 7 '13 at 1:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.