8

i've a CentOS 6.5 KVM Host with 3 KVM-Guest CentOS 6.5. Now I want to assign a public IP for the host and one public IP for each guest using a single network interface. My IPs (assigned by network administrator) are:

  1. 10.25.147.100
  2. 10.25.147.101
  3. 10.25.147.102
  4. 10.25.147.103

Mask: 255.255.254.0

Gateway 10.25.146.9

Here's an image that explains better my situation:

http://oi60.tinypic.com/w1tjl2.jpg

I'm a newbie with linux, so please help me :)

Thanks in advance

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Tinez Ridan
  • 81
  • 1
  • 2

2 Answers2

1

You can use a Bridge on the Host-Server. The other KVMs will use a static IP.

How to create a Bridge: Link. Now you just have to use the Bridge in your KVMs. If you use virsh with the argument --network=bridge:br0

To install a new VM with help from virsh, I am using this command:

virt-install --connect qemu:///system --name test_vm --ram 1024 --vcpus 2 --disk path=/vms/test_vm.img,size=10 \
             --network=bridge:br0 \
             --os-type=linux --graphics vnc,password=test --autostart --virt-type kvm

Special the 2. line is telling the simulator to use the bridge br0. The Linux-Kernel is automatically creating the tap devices for the bridge, you can check this with ifconfig.

A VM need's now a static IP. In CentOS you have to edit /etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE="eth0"
BOOTPROTO="none"
HWADDR=
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID=
IPADDR=10.25.147.10*
NETMASK=255.255.254.0
DNS1=10.25.146.???
GATEWAY=10.25.146.9
peterus
  • 21
  • 3
  • thanks for your link, can you show me how to set a single bridge for multiple ip? In your example there's only one. – Tinez Ridan Jan 29 '14 at 13:42
  • which KVM lib are you using? you have to generate *one* bridge like shown in the link. Just tell the KVMs to use this bridge instead of the eth0. You don't have to generate more bridges. I am generating my vms like this: `virt-install --connect qemu:///system --name test_vm --ram 1024 --vcpus 2 --disk path=/vms/test_vm.img,size=10 --network=bridge:br0 --os-type=linux --graphics vnc,password=test --autostart --virt-type kvm` All the VMs are using br0. The kernel is automatic generating the tap devices (`ifconfig`). – peterus Jan 29 '14 at 14:22
  • I've KVM libvirt qemu and I've already installed 3 guests. With one bridge on eth0 is it possible to assign a separate public ip to each guest? I need to assign the IPs i've mentioned in the first post. – Tinez Ridan Jan 29 '14 at 19:33
  • A way to put a static IP on a Server is posted in the answer. Just edit all the files in the VMs and put the corresponding IPs. Don't forget to put the correct DNS server. – peterus Jan 30 '14 at 08:35
0

Your picture is wrong - you cannot assign IP addresses outside of the KVM hosts, but only inside in the KVM hosts.

If you want assign 3 IP address for 3 KVM machines, you have to use KVM switch and IP address assign in every KVM hosts (and only in the KVM hosts!). They will be communicate through software switch and you will see they under they're addresses.

Jan Marek
  • 2,120
  • 1
  • 13
  • 14