VitualBox Host Only Adapter & NAT configuration.


Oracle Virtualbox is great virtualisation  solution for developers. The best feature of VirtualBox is, "it's free" and its runs on Linux, Mac & Windows.
Many time when people want to set up Virtualbox they have two common requirements.

1. To connect to internet from guest i.e. the virtual machine.
2. To be able to connect to virtual machine from host computer.

Now let's talk on solution. Requirement '1' can be met with configuration of 'NAT', like in screenshot below. This will enable the virtual machine to connect to internet.




Now we want to enable LAN sort of connectivity between host and guest machines. For this we have to follow following steps.

1. Create a host only adapter by going to Virtualbox > Preferences

2. Add a host only adapter as shown.



3. Setup up DHCP if you want. I personally don't like DHCP, so my example will have manual setup in it. If you are following this example, be sure to uncheck DHCP configurations. You can choose any IP range and any subnet mask, given they do not conflict. Advised use class "C" network addressing and subnet mask as 255.255.255.XXX where XXX should not match the subnet mask of your primary adapter from which you connect to internet, i.e. if your primary adapter is 255.255.255.0, do not use the same subnet mask.



4. Add this adapter as host only adapter to the virtual machine you created.  Be sure that NAT is your "Adapter 1" & Host only is your "Adapter 2". Most operating systems use this precedence to determine where your internet traffic will be routed.



5. Since you have not used DHCP, you need to set up static IP in your vital machine. Static IP assignment commands and files differ from operating system to operating system. I am using Debian flavor so I changed "/etc/network/interafces" as following. I added "address", "netmask" same as defined in step 3, "network", "broadcast" & "gateway" as IP address of the adapter defined in step 3.



6. Try to ping any internet site (I tried with google.com) from inside the virtual machine. This ping should work.



7. Try to ping the IP you configured in step 5 from host network. This should also work.



If all these steps work as shown, you will achieve the NAT outward and Host adapter inward configuration. Be sure that "NAT" should be first adapter and "Host Only" should be second adapter.

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java