Mittwoch, 30. November 2011

Accessing the host network from a KVM guest

KVM guests can be created and installed very easy by the use of a NAT network. However, with that you cannot access the network on your host as both networks are working in a different network.
The solution is to install the bridge-utils and configure a tun/tap network, which will allow the network access to the host system.

Here an example for Ubuntu 12.04:

  • installing the needed packages
sudo apt-get install bridge-utils
sudo apt-get install uml-utilities

  • make a backup of your original network configuration file
sudo cp /etc/network/interfaces /etc/network/interfaces.backup

  • edit the network configuration file similar to this

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto tap0
iface tap0 inet static
pre-up tunctl -u $USER -t $IFACE
post-down tunctl -d $IFACE
address 172.100.1.111
netmask 255.255.0.0

auto br0
iface br0 inet static
address 172.100.1.110
network 172.100.0.0
netmask 255.255.0.0
broadcast 172.100.0.255
gateway 172.100.0.1
bridge_ports eth0 tap0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
  •   restart the network
 sudo /etc/init.d/networking restart

  • start the KVM guest for example with a similar shell script like this:
#!/bin/sh
/usr/bin/kvm  -soundhw es1370 -k de -vga vmware \

-enable-kvm -m 3072 -localtime \
-hda "/vm/vm-images/ubuntu1004_32b"  \
-boot once=c,menu=off \
-net nic,vlan=0,macaddr=52:54:00:7b:95:22 \
-net tap,vlan=0,ifname=tap0,script=no \
-name "Ubuntu 10.04 32B" $*


 voilá :-)