How to share internet access between Ubuntu and Windows guests OS in VirtualBox?

Using VirtualBox.

There's two Virtual Machines, Ubuntu 10.04 and Windows 7.

On Ubuntu:

There's two ethernet interfaces.

  • Bridge interface (eth0) who can access the internet. ping www.google.com works ok.
  • NAT interface (eth1) configured as Internal Network who have ip 10.0.0.101, netmask 255.255.255.0 and gateway 10.0.0.1 who can ping Windows 7 in 10.0.0.102.

On Windows

  • A interface who have ip 10.0.0.102 and can ping Linux in 10.0.0.101 ok, but can't ping www.google.com.

So, how can I configure Windows to have access to the internet using my Linux machine?


Solution 1:

Ok it works like this, when you are INSIDE the virtual environment just forget about virtualbox. Assumming you have the following setup, it should all work out:

MAIN HOST (The one where you are running virtualbox with both guess insides) - It should have an internet access. Does not matter if it through a proxy, inside an intranet or a normal connection to your ISP. It should have access to the internet.

VIRTUALBOX - VIRTUAL HOST (UBUNTU) - It should have one network connection to your MAIN HOST which provides internet and one network connection (Called by default Internal Network) which we will use to share the connection. It should be noted that after finishing the whole sharing explanation this can also work if the HOST is Windows.

VIRTUALBOX - VIRTUAL GUEST (WINDOWS) - It should have one network connection to the "Internal Network".

With all of this setup in that specific way you can do the following:

VIRTUAL HOST (Ubuntu)

  1. In your Ubuntu 10.04 go to Connection Indicator in the Panel (Network Manager Applet)
  2. Go to Edit Connections.
  3. Select your INTERNAL NETWORK interface (Since you will see 2, example eth0 and eth1. One of them is the internal one that connects to the rest of the virtual guests and the other one connects to your MAIN HOST) and open it.
  4. Go to IPv4 Settings and in the Method field select "Shared with Other Computers".
  5. Apply and you are done with the VIRTUAL HOST (Ubuntu). Now for the VIRTUAL GUEST (Windows).

NOTE - Some people might suggest a little more complicated iptables, masquerade console commands. There is no need for this since (I think) Ubuntu 9.04 or higher. Since the Network Manager updated itself several years ago everything from Modem, Cellphones and shared wifi connections has been easier than ever.

VIRTUAL GUEST (Windows)

Go to the "Network Manager" in Windows and select the only connection you have. Go to the Ipv4 TCP Protocol and verify that it has the IP set to Dynamic/Auto. It should now see the connection from the ubuntu box. IF by any case it does not work, since you have Windows 7 which includes a pretty nifty way of checking for internet acces you should run this tool from the network manager in windows and make it look for the internet. in this same manner I have made around 50 setups for windows xp, windows vista and windows 7. Most of which are for windows 7. So I might be going out of a limb here but for 50 tests am pretty sure this will work ^^.

NOTE - There is actually no need for a DHCP Server like in Ubuntu server to share. There is also no need for a DNS server in windows. The default setup that comes in ubuntu and windows can deal with a simple task like this. The thing to remember here is that, when inside the virtual environment just forget about the host. Imagine yourself in a lan party with 2 PCs which one has an internet connection and another connection to the lan and the other PC wants to have internet shared to. Eliminating the association between the virtual place and the real place (MAIN HOST) helps in solving several network problems.

NOTE 2 - Additional you NEED (Let me rephrase that, YOU REALLY REALLY!!! NEED) to use the version from VirtualBox and the Extension of Virtualbox to have everything working as it should. The latest version up to this moment which is the 4.1.4 version which came on October 3rd has many problems solved and since version 4.1.2 I can vouch that the horrible problems about random mouse movement and sharing virtual folders is gone.

The latest version can be found here: https://www.virtualbox.org/wiki/Linux_Downloads

And the extension for the latest here: https://www.virtualbox.org/wiki/Downloads

Why am I making such a big fuss over using the Virtualbox from the site and not a PPA or the OSE version. Because first Virtualbox will add after installing the package (Just double click it after downloading it) the ppa or repo to get the latest updates. Second the OSE has many less features than the one in the webpage (This difference started from when innotek was the main company and in those days OSE and virtualbox normal were the same). Now the virtualbox from the main page has way too many more things. Also many PPA out there are obsolete or not updated so fast as the main repo from virtualbox.

NOTE 3 - Since Virtualbox 4.1.4 there is no need to download the extension again. Virtualbox will automatically check to see if the extension is compatible or up to date with the latest version installed. But you still need to install it if you haven't yet done so. At least the first time. After that there is no more need to do it.