12 December 2008

VirtualBox host interface networking on Ubuntu

For 99% of my work I can use Ubuntu. But for some bad software I need Windows because that software is even not running in Wine. For that purpose I have set up a Windows virtual machine using VirtualBox.

Installing VirtualBox on Ubuntu is very easy:
sudo apt-get install virtualbox-ose virtualbox-ose-modules-`uname -r`
You can now create virtual machines in GUI mode with VirtualBox. Your virtual machine uses NAT networking by default. Most internet and networking applications can work well with that. But some Windows applications still use NetBIOS functionality instead of TCP/IP and that is not routable. To get NetBIOS work, you need to configure your virtual machine to use host interface networking.

For host interface networking you need to configure a network bridge. Because I am not a network specialist, I have googled around, tried many options and ended in the setup I am describing now. Maybe it is not really the best way to do this, however it is working well.
  • edit /etc/network/interfaces:
    sudo vi /etc/network/interfaces
    • remove all lines referring to eth0 (assuming this is the active NIC) and insert the lines below:
      auto br0
      iface br0 inet dhcp
      bridge_ports eth0
      bridge_fd 9
      bridge_hello 2
      bridge_maxage 12
      bridge_stp off

      auto eth0
      iface eth0 inet manual
  • restart networking:
    sudo /etc/init.d/networking restart

  • create virtual NIC:
    sudo VBoxAddIF vbox1 $USER br0
  • edit VirtualBox interfaces config:
    sudo bash -c "echo \"vbox1 $USER br0\" > /etc/vbox/interfaces"
  • setup your (Windows) guest to use host interface networking with device vbox1 now