<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Blog entries tagged virtualbox :: mwop.net</title>
  <updated>2009-01-17T10:43:40-06:00</updated>
  <generator uri="https://getlaminas.org" version="2">Laminas_Feed_Writer</generator>
  <link rel="alternate" type="text/html" href="https://mwop.net/blog/tag/virtualbox"/>
  <link rel="self" type="application/atom+xml" href="https://mwop.net/blog/tag/virtualbox/atom.xml"/>
  <id>https://mwop.net/blog/tag/virtualbox</id>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[VirtualBox Networking]]></title>
    <published>2009-01-17T10:43:40-06:00</published>
    <updated>2009-01-17T10:43:40-06:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/205-VirtualBox-Networking.html"/>
    <id>https://mwop.net/blog/205-VirtualBox-Networking.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I use Linux on the desktop (currently <xhtml:a href="http://www.ubuntu.com/">Ubuntu</xhtml:a>), but occasionally need to use
Windows for things like webinars, OS-specific testing, etc. I
started using <xhtml:a href="http://virtualbox.org/">VirtualBox</xhtml:a> for
virtualization around six months ago, and have been reasonably
satisfied; Windows boots quickly, and everything "just works." That
is, until yesterday.</xhtml:p>
<xhtml:p>I was given a linux VM image running a web server and some
applications I needed to review. On top of that, I needed to do so
over WebEx, so that I could share my screen with somebody else.
This meant I needed the following to work:</xhtml:p>
<xhtml:ol>
<xhtml:li>Internet access for my Windows VM</xhtml:li>
<xhtml:li>Access to my linux VM from my Windows VM</xhtml:li>
<xhtml:li>Ideally, access to both guest VMs from my linux host</xhtml:li>
<xhtml:li>Ideally, internet access for my linux host</xhtml:li>
</xhtml:ol>
<xhtml:p>Since I'd only ever used one VM image at a time before this, I'd
never had any issues; I could use NAT networking in VirtualBox, and
have communication between my host and guest, as well as internet
access for both. But NAT access does not allow the VMs to
communicate with each other — in fact, both received the same exact
same IP address from my host, which meant that I had internet
access from both, both could ping the host, but the host could not
access either machine, and neither could access each other.</xhtml:p>
<xhtml:p>I did some research, and started reading on using network
bridges, something I'd tried once before without success.
Fortunately, the very first literature I started reading this time
pointed out the reason why I'd failed before: network bridges over
wireless adapters do not work, and I was using my wifi. I briefly
considered using a wired connection, but realized that this was not
an option: there are times I may need this sort of setup when I am
unable to use a wired connection.</xhtml:p>
<xhtml:p>I then found an article that detailed how to setup Host
Interface networking with VirtualBox. Host Interface networking was
added in the 2.1.x series of VirtualBox, and basically allows you
to use your host machine as a network gateway for your guest
machines. The VirtualBox binaries available in Ubuntu are 2.0.x… so
I had to uninstall them and download the official binaries from the
VirtualBox site.</xhtml:p>
<xhtml:p>Setting up Host Interface networking worked for case 2 only;
somehow, when it was active, my routing got completely borked. So,
I did more research. The next thing I found suggested I needed to
setup one or more <xhtml:a href="http://vtun.sourceforge.net/tun/faq.html">virtual network
devices</xhtml:a> (TAP), which would allow each virtual machine to have
its own IP address, and communicate over the same network, while
using the wifi adapter in my host machine as a gateway to the
internet.</xhtml:p>
<xhtml:p>All the instructions I found setup a separate TAP interface for
each virtual machine. I quickly discovered two things: first, I had
to setup IP masquerading in my host's iptables rules so that the
VMs would have access to the internet, and second, that while this
would solve cases 2-4, the VMs still couldn't talk to each other.
In the end, I found that I needed to setup a single TAP interface,
and have all the VMs use this as their Host Interface — and
everything then worked. Almost. The other trick I discovered was
that the TAP address should be on a private network that you're not
a member of already — including the private network space your
router might use. The instructions I followed setup the network in
the 10.0.1.X network, but this conflicted with my DSL modem, which
was assigned a 10.0.0.X address, and meant that the guest machines
had no access to the outside world; switching to 192.168.168.X
fixed all issues.</xhtml:p>
<xhtml:p>Here are the step-by-step instructions (linux host):</xhtml:p>
<xhtml:ul>
<xhtml:li><xhtml:strong>On the host:</xhtml:strong>
<xhtml:ul>
<xhtml:li>Make sure you have uml-utilities installed
<xhtml:ul>
<xhtml:li>On Debian-based systems, <xhtml:code>sudo aptitude install
uml-utilities</xhtml:code></xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li>Create a virtual network interface
<xhtml:ul>
<xhtml:li><xhtml:code>sudo tunctl -t tap0 -u $USER</xhtml:code> (where
<xhtml:code>$USER</xhtml:code> is the user initiating the VirtualBox sessions
<xhtml:ul>
<xhtml:li>Make sure the user is in the vboxusers group:
<xhtml:ul>
<xhtml:li>Edit <xhtml:code>/etc/group</xhtml:code>, look for the
<xhtml:code>vboxusers</xhtml:code> entry, and ensure <xhtml:code>$USER</xhtml:code> is
listed as a member of the group.</xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li>Make sure the vboxusers group has rights to tun devices:
<xhtml:ul>
<xhtml:li><xhtml:code>sudo chgrp vboxusers /dev/net/tun</xhtml:code></xhtml:li>
<xhtml:li><xhtml:code>sudo chmod 660 /dev/net/tun</xhtml:code></xhtml:li>
</xhtml:ul>
</xhtml:li>
</xhtml:ul>
</xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li>Enable the network interface and assign it an IP address
<xhtml:ul>
<xhtml:li>Make sure the IP is not on a netmask in use elsewhere in your
networking; I used 192.168.168.1, which did not conflict with
anything.</xhtml:li>
<xhtml:li><xhtml:code>sudo ifconfig tap0 192.168.168.1</xhtml:code></xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li>Set up NAT forwarding:
<xhtml:ul>
<xhtml:li><xhtml:code>sudo iptables -t nat -A POSTROUTING -o wlan0 -j
MASQUERADE</xhtml:code>
<xhtml:ul>
<xhtml:li>Substitute the appropriate network interface based on what
you're using on your machine.</xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li><xhtml:code>sudo sysctl -w net.ipv4.ip_forward=1</xhtml:code></xhtml:li>
</xhtml:ul>
</xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li><xhtml:strong>On your guest machines:</xhtml:strong>
<xhtml:ul>
<xhtml:li>Setup TCP/IP networking to use static IP addresses in the
network you've defined for the virtual adapter on the host. For
example, if you used 192.168.168.1 on your host:
<xhtml:pre><xhtml:code class="language-yaml hljs yaml" data-lang="yaml"><xhtml:span class="hljs-attr">Address:</xhtml:span>
<xhtml:span class="hljs-number">192.168</xhtml:span><xhtml:span class="hljs-number">.168</xhtml:span><xhtml:span class="hljs-string">.[UNIQUE]</xhtml:span>
<xhtml:span class="hljs-attr">Netmask:</xhtml:span>
<xhtml:span class="hljs-number">255.255</xhtml:span><xhtml:span class="hljs-number">.255</xhtml:span><xhtml:span class="hljs-number">.0</xhtml:span>
<xhtml:span class="hljs-attr">Gateway:</xhtml:span>
<xhtml:span class="hljs-number">192.168</xhtml:span><xhtml:span class="hljs-number">.168</xhtml:span><xhtml:span class="hljs-number">.1</xhtml:span>
</xhtml:code></xhtml:pre></xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li>Assign DNS servers based on what you're using on your linux
host. Check <xhtml:code>/etc/resolv.conf</xhtml:code> if you're unsure.</xhtml:li>
</xhtml:ul>
<xhtml:p>Now, one caveat: your TAP device will disappear when you restart
your host box. To solve this, I added the following lines to my
<xhtml:code>/etc/rc.local</xhtml:code>:</xhtml:p>
<xhtml:pre><xhtml:code class="language-bash hljs bash" data-lang="bash"><xhtml:span class="hljs-built_in">echo</xhtml:span> -n <xhtml:span class="hljs-string">"Setting up tap0 interface..."</xhtml:span>
tunctl -t tap0 -u matthew
ifconfig tap0 192.168.168.1
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1
<xhtml:span class="hljs-built_in">echo</xhtml:span> <xhtml:span class="hljs-string">"DONE!"</xhtml:span>
</xhtml:code></xhtml:pre>
<xhtml:p>This ensures that the TAP device is setup, and also that IP
masquerading is enabled at boot time.</xhtml:p>
<xhtml:p>I'm writing this mainly for myself, but also hoping that it will
save others the many hours of experimentation I had to go through
to find the write combination of settings.</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/205-VirtualBox-Networking.html">VirtualBox
Networking</xhtml:a> was originally published <xhtml:time class="dt-published" datetime="2009-01-17T10:43:40-06:00">17 January 2009</xhtml:time> on
<xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
</feed>
