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.
·
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)
To make this work requires the following steps:
Setup the Host Network Adapter in VirtualBox
1.
Start VirtualBox
3.
On the left side, select 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”
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.
3.
Select OK to close the settings dialog.
4.
Start the VirtualBox VM
Set the Network in the VirtualBox VM
Set the Network in the VirtualBox VM
1.
Log in as root
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.
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.
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
11.
Restart the VirtualBox VM
Update the Windows Hosts File
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
10.88.12.4 dev.example.com dev
3.
Save and close the host file.
Verify Virtualbox VM can reach the internet and itself
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
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)