Wednesday, March 6, 2013

How to configure Virtual Box with internet and host access


I have had such a hard time locating the information I needed to get a VirtualBox VM to use both NAT and Host networks so that the VM could see the internet and the host could see the VM with a known IP address that I decided to write this post.

The configuration in this post is as follows:
·         Host O/S is Windows 7 (64 bit)
·         VirtualBox is version 4.2.6 r82870
·         Guest O/S is Oracle’s Enterprise Linux 5 (64 bit)
·         Guest has a web server installed and running.

To make this work requires the following steps:

Setup the Host Network Adapter in VirtualBox

1.       Start VirtualBox
2.       Select the File menu and Preferences
3.       On the left side, select Network

4.       In the network dialog, select the  to add a new host only network



5.       Follow the prompts for locating the driver for the new network. On my machine, the file is located at “C:\Program Files\Oracle\VirtualBox\drivers\network\netadp”
6.       Double click on the new adapter; “VirtualBox Host-Only Ethernet Adapter #3” in this example.

7.       Change the settings as shown here



8.       Select OK to close the Host-Only Network Details
9.    Select OK to close the VirtualBox – Settings dialog.

Set up the VirtualBox VM

1.       With the VM shutdown, select the Settings for the VM and open the Network dialog and set Adapter 1 as shown here and refresh the MAC Address. No Port Forwarding is required.



2.       Set Adapter 2 as seen here and refresh the MAC Address as well



3.       Select OK to close the settings dialog.
4.       Start the VirtualBox VM

Set the Network in the VirtualBox VM

1.       Log in as root
2.       Select System -> Administration -> Network



3.       It should look similar to the following



4.       Select the eth0 device and Edit. Verify that it looks like the following. If not then change it.
eth0 is set for DHCP



There are no static routes defined



and the hardware matches the VirtualBox Adapter 1 hardware and MAC address.



5.       Select OK to save any changes
6.       Select the eth1 device and Edit. Verify that it looks like the following. If not then change it.
Set the IP Address and Subnet mask



There are no static routes defined



and the hardware matches the VirtualBox Adapter 2 hardware and MAC address.



7.       Select OK to save the changes
8.       Add your new IP Address and host name to the hosts file



9.       Save and exit the network configuration
10.   Open a terminal and restart the network



11.   Restart the VirtualBox VM

Update the Windows Hosts File

1.       Edit the hosts file (c:\windows\system32\drivers\etc\hosts). Note that Windows hides the etc folder so you will need to either show all hidden folders or type the path in.
2.       To the hosts file add
10.88.12.4  dev.example.com dev
3.       Save and close the host file.

Verify Virtualbox VM can reach the internet and itself

1.       When the VirtualBox VM is restarted, log in as a non-root user
2.       Start the web browser
3.       Verify internet connection by selecting a known site such as www.google.com
4.       Verify the local web server by http://dev (or whatever your VirtualBox VM hostname is)

Verify the Windows Host can connect to the VirtualBox VM

1.       Open a web browser
2.       Verify internet connection by selecting a known site such as www.google.com
3.       Verify the local web server by http://dev (or whatever your VirtualBox VM hostname is)


In this configuration, your host can access the VirtualBox VM and the VirtualBox VM can access the internet but the VirtualBox VM is not visible to others.

13 comments:

  1. Thank You very much. This helped. Now I can get my mom to try linux and maybe get her to install opensuse 13.1 as her default.

    ReplyDelete
  2. Thanks for the post. I am trying it with VirtualBox 4.3 and the network adapter menus don't give the option to set up the IPs trough the GUI anymore :S

    ReplyDelete
  3. Thank you very much. Can you please explain the difference between the ipaddress of the adapter 10.8.12.0 to that is set on the guest 10.8.12.4. I'm a newbie and don't have a good grasp on networking.

    ReplyDelete
  4. Thanx for the post man it really help me..to get our of the problem which i was suffering from last night...love you

    ReplyDelete
  5. Hi! what would i do if i need to connect to other PC but i don't have internet connection

    ReplyDelete
  6. I need to internet connection to checkout files from the net that's why i need internet conenction in my VM...thanks

    ReplyDelete
  7. Might be helfull vor Oracle VM virtual box # 4.3.30 still fighting to have internet connection
    from my guest WIN XP (32 bits)on my external HD. My host system is WIN 7 64 bits

    ReplyDelete
  8. Making money on the Internet is not as hard as many people believe, because the only thing you need to start making money on the internet is to start an internet business. charge gmail username

    ReplyDelete
  9. I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work. dish internet

    ReplyDelete
  10. I love smoothies and this one looks so yummy!

    ReplyDelete
  11. And it is true! Landline phone services have been relegated to the past--it is Voice over Internet Protocol now (VoIP). You save on costs and save on time!
    showboxdownloadsapp.com

    ReplyDelete