Freitag, 13. Dezember 2013

KVM networking with guests having static public ip addresses

In this blogpost I will show you how to setup kvm networking in the way that guest IPs are mapped to the local network. This way it is possible have guests running on the host with external/public IP addresses. At first kvm should be already installed, additionally we should check if bridge-utils is already installed.
 
sudo apt-get install bridge-utils

Assuming the following scenario:
  • host system ip configuration:
    •   IP: 10.10.10.5
    • netmask: 255.255.0.0
    • Gateway: 10.10.0.1
    • DNS: 10.10.0.250, 10.10.0.251
  • guest ip configuration:
    • IP: 10.10.10.10
    • netmask: 255.255.0.0
    • Gateway: 10.10.0.1
    • DNS: 10.10.0.250, 10.10.0.251
We have to edit /etc/network/interfaces to enable the bridges. Currently my interfaces file looks like that:

auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
       address 10.10.10.5
       netmask 255.255.0.0
       gateway 10.10.0.1
       dns-nameservers 10.10.0.250 10.10.0.251 


This has to be changed in the following way:
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
       address 10.10.10.5
       netmask 255.255.0.0
       gateway 10.10.0.1
       dns-nameservers 10.10.0.250 10.10.0.251 
       bridge_ports eth0
       bridge_stp off
       bridge_fd 0
       bridge_maxwait 0
Now we have to restart networking to incorporate the changes.
/etc/init.d/networking restart

After that we can run vmbuilder to create a new machine with the corresponding client ip configuration.
vmbuilder kvm ubuntu --suite=precise --flavour=virtual --arch=amd64 
--install-mirror=http://apt-cacher-ng:3142/ubuntu -o --libvirt=qemu:///system 
--ip=10.10.10.10 --gw=10.10.10.1 --part=vmbuilder.partition  --templates=templates/ 
--user=admin --name=admin --pass=pass --addpkg=acpid 
--firstboot=/opt/kvm/images/vslave-001/vmbuilder.boot.sh 
--mem=4096 --hostname=build-vslave-001 --bridge=br0 


  • https://help.ubuntu.com/community/KVM/Networking
  • http://docwiki.cisco.com/wiki/OpenStack:VM_Build
  • http://foswiki.org/Support/UbuntuVmBuilder
  • http://www.fak-online.net/?p=22
  • http://www.linux-kvm.org/page/Networking
  • http://blog.braastad.org/?p=128
  • http://www.howtoforge.com/virtualization-with-kvm-on-ubuntu-12.04-lts

Keine Kommentare:

Kommentar veröffentlichen