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

auto br0
iface br0 inet static
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:
/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á :-)

Keine Kommentare: