How to set host-only adapter on VM (Virtual box)

isabolic99 profile image isabolic99 Updated on ・2 min read

You can find many tutorials about how to setup host-only adapter, but most of them are incomplete, something is missing. So I decided to provide a step-by-step guide from my personal notes.

1) Configuration of network adapter

In newer versions of VirtualBox select from File menu > Host network manager.

Create new adapter, and set the following options:
Configure the adapter manually.

ipv4 address
ipv4 network mask
DHCP server checked
Server address
Server mask
Lower address bound
Upper address bound

You can set IP address whatever you like, but make sure that other options are also set to appropriate address (DHCP server address, Lower/upper address bound, conf. of the network interface on VM)

2) Set up the adapter in network settings of VM

Then, in the network settings for the virtual machine (machine tools icon - hammer), set up two adapters:

Adapter 1
host only, vboxnet0


also don't forget to click on refresh mac address of both adapters

3) Configure the VM

Boot the virtual machine and log in through the console VirtualBox provides.

open the terminal and run the following command:

ls /sys/class/net

This will provide you the name of adapters on the VM. In my case, the adapters were named eth1 and eth2 (and lo, the loopback interface).

Then, edit the network configuration.

sudo vi /etc/network/interfaces

Now apply the following configuration:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface host-only adapter
auto eth0
allow-hotplug eth0
iface eth0 inet static

# The NAT
auto eth1
iface eth1 inet dhcp

After that, I recommend restart of VM.

And that is it. Now I am too lazy to explain every option in network interface configuration (hotplug etc..). You can google itself. :P

Also, you can set the hostname in your host's file (win => C:\Windows\System32\drivers\etc\hosts, linux => /etc/hosts) so you don't have to every time access to VM by ip address.

My hole developer environment (and playground) is on VM, there I have installed tomcat, apache, db, node.js etc. because I don't want to pollute my host machine and also by my opinion this is the best solution for simulation of production/test environment.

Posted on by:

isabolic99 profile



The lover of javascript, good coffee and cycling.


markdown guide