Here a quick quide on how to install KVM, libvirt and virtual machines. This has been tested with Hetzner, Softlayer and OVH and should work with all major dedicated server providers.
You will need extra IP addresses for the virtual machines, so make sure to order an extra subnet for your server.
1. Install the needed packages
apt-get install qemu-kvm libvirt-bin
2. Enable ip_forward by adding the following line to /etc/sysctl.conf
Activate the change by running
3. Configure libvirt for your additional subnet
Enter virsh by typing virsh in the command line. To make changes to the default network with the net-edit command, you first have to destroy the network and then start it again, otherwise net-edit won’t save the changes.
virsh # net-destroy default Network default destroyed
virsh # net-edit default Network default XML configuration edited.
Change the configuration so that it looks similar to the one below. The value for ip address is the network address of your subnet. If for example you have been provided with an additional subnet 188.8.131.52/29 the network address is 184.108.40.206.
Start the network again.
virsh # net-start default
4. You can now install your virtual machines. The easiest way to install a virtual machine is from an iso image with the Virtual Machine Manager. The iso image should be placed into /var/lib/libvirt/images/.
cd /var/lib/libvirt/images/ wget http://releases.ubuntu.com/precise/ubuntu-12.04-server-amd64.iso
Then start virt-manager on your computer, connect to the server and install the virtual machines.
After installing the VM you will need to update its network configuration so it can connect to the internet. Make sure to set the gateway to your servers main ip address, to add a line pointopoint with the same ip address and to set the netmask to 255.255.255.255. Here an example of /etc/network/interfaces:
The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 220.127.116.11 netmask 255.255.255.255 network 18.104.22.168 broadcast 22.214.171.124 gateway 126.96.36.199 pointopoint 188.8.131.52
If you have troubles with DNS also check if /etc/resolv.conf exists and if it contains a valid nameserver.