June 22, 2014

Creating host-only network in a corporate environment: Oracle VirtualBox

Suppose we have to create a host-based network (i.e. a network where a host machine and all virtual machines will be visible to each other but won't "see" the external network) on a host machine that is already connected to a corporate network. To do this without disrupting the existing network settings, you can use the Oracle VirtualBox DHCP server.

For example, your machine has an IP address 192.168.0.22 in the corporate network. You can choose some other private IP address range for your virtual network ‒ say, 172.16.x.x. This will allow you to quickly distinguish the virtual network IP addresses from your corporate network ones.

To illustrate the concept, consider a small network consisting of your host and two virtual machines (Windows 7 in our example). The IP addresses can be arranged like this:

  • 172.16.0.0 ‒ DHCP server. As mentioned above, we'll use the VirtualBox DHCP server.
  • 172.16.0.1 ‒ your host machine. Of course, this IP address will be used by the Virtualbox network adapter, not your Ethernet adapter for Local Area Connection.
  • 172.16.0.2 ‒ the first virtual machine.
  • 172.16.0.3 ‒ the second virtual machine.

Assuming you have already created two Windows virtual machines, let's begin.

First, we'll change VirtualBox DHCP server settings and your host IP address in the virtual network. Open the File menu, then Preferences. In the "VirtualBox ‒ Settings" dialog box, select Network. In the "Host-only Networks" tab, click on the VirtualBox Host-Only Ethernet Adapter and press the "Edit host-only network" button on the right:

In the Adapter tab, change the IPv4 Address to 172.16.0.1 (your host IP address):

In the DHCP Server tab, fill in the Enable Server checkbox and change the settings like this:

  • Server Address: 172.16.0.0
  • Lower Address Bound: 172.16.0.2
  • Upper Address Bound: 172.16.0.254

After you press OK, your firewall can prompt you that new network is detected. You can select the option named like "I am at HOME":

Now select your first virtual machine and change its network settings. In the Network setting, select the Adapter 1 tab and do the following:

  • Fill in the Enable Network Adapter checkbox;
  • In the "Attached to:" drop-down list, select "Host-only Adapter";
  • Expand the Advanced settings and ensure that the "Cable Connected" checkbox is filled in.

Start the first virtual machine. Once inside, press Start, go to Control Panel → Network and Internet → Network and Sharing Center → Change adapter settings. You should see the Local Area Connection icon; right-click on it and select Properties. In the properties dialog, select "Internet Protocol Version 4 (TCP/IPv4)" and press the Properties button. In the General tab, select "Use the following IP address:" and fill in the fields like this:

  • IP address: 172.16.0.2
  • The Subnet mask field should be filled in automatically; otherwise, enter 255.255.0.0
  • Set the default gateway to your VirtualBox DHCP Server address (172.16.0.0 in our example)

You can leave the DNS server settings empty.

Your virtual machine will likely to prompt you to choose the network location. Once again, you can select "Home network":

To check your new settings, run Windows Command Prompt inside your virtual machine and try to ping your host:

> ping -a 172.16.0.1

If the ping fails, check all your steps once again.

Finally, run Windows Command Prompt on your host machine and try to ping your first virtual machine:

> ping -a 172.16.0.2

If all is OK, change the second virtual machine in a way similar to the first one. Don't forget to change the IPv4 address as appropriate (for our example, to 172.16.0.3).

No comments:

Post a Comment