LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (http://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Assign IP to Guest VM in KVM (http://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/assign-ip-to-guest-vm-in-kvm-834520/)

vzxen 09-26-2010 12:56 AM

Assign IP to Guest VM in KVM
 
I have a server with 5 Public IPs.
I have installed CentOS as Host and KVM virtualization.
Creating a Guest is simple using virt-manager.

I wanted to know how to give one Public IP out of the 5 to a Guest VM.
In OpenVZ its pretty simple as you can use vzctl 101 --ipadd.

How to do this in KVM ?

acid_kewpie 09-26-2010 01:00 AM

you don't do it in kvm, you do it within the guest operating system. KVM doesn't care about the IP addresses you're using and clearly has no way to reach inside the VM and configure it automagically, why should it? Just configure the guest appropriately like any other operating system install on a physical machine.

vzxen 09-26-2010 06:52 AM

You mean to configure /etc/sysconfig/network-scripts/ifcfg-eth0
I have done that and indeed it works as well.

But what if the user adds two IPs himself.
How will that be controlled ?

Ramurd 09-26-2010 05:25 PM

either by bridging or setting up a vde lan (best way to go imo due to privileges)

vzxen 09-26-2010 11:51 PM

Is there any bridging guide ?
Also by "vde lan" you mean a virtual device right ?

Ramurd 09-27-2010 12:49 AM

There are quite alot of bridging guides, essentially what you have to do on your host system is create a bridge device and attach it to your virtual machine using the tun/tap devices.

With vdelan I do not really mean virtual device, that's about eveything on a virtual machine ;-) I mean Virtual Distributed Ethernet. In short: a virtual switch. You can connect to that if you define your net device with if=vde (you also need a "real" interface, for which I use virtio)

you then get -net vlan=0,if=virtio,macaddr=01:23:45:67:89 -net vlan=0,if=vde

For that you only need one tap device, which you can create at boot time (doesn't really hurt) on your host. Adding dnsmasq and attach it to that device and you have a dynamic solution that offers near everything in this regard.

AlienBOB wrote some nice stuff about this. Although it is based on a Slackware host, I think you can pick some nice candies of knowledge out of it:
http://wiki.alienbase.nl/doku.php?id=slackware:vde

vzxen 09-27-2010 02:33 AM

Do the Virtual Machines get IPs like 10.0.0.x by default ?
Cant we use iptables to forward in this case ?

Ramurd 09-28-2010 12:13 AM

There are no default IP numbers for the virtual machines; you define the addresses that should be assigned with dnsmasq. Then again: addresses like 10.x.x.x are good values for being safe to use internally.

You can use iptables to forward them indeed; addresses need only to be known to the host that forwards the ports.

vzxen 09-28-2010 01:34 AM

The following CentOS documentation mentions it does :
http://wiki.centos.org/HowTos/KVM#he...cf987d04f7fc96

Also in the bridging method, do I have to create a new bridge for each Virtual Machine ?

acid_kewpie 09-28-2010 04:14 AM

no, you don't create a new bridge unless you want to, i.e. you have a different address space and requirements from it. I'm currently building a very bespoke kvm / qemu environment with about 14 bridges between 8 VM's, but in a simple environment you would often only have a single bridge, default, onto which all VM's would be hooked. if you're using virt-manager then there, as I understand it, a short coming in the network tpyes in that you can create routing bridges and nat bridges, but not transparent bridges, where your VM ip's would be in the same address space as the other physical machines in the environment. This can be created very easily on the machine though outside of virt-manager


All times are GMT -5. The time now is 12:48 PM.