DEV Community


Posted on • Updated on

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

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (3)

psycomentis06 profile image
Amor Ali • Edited

Thanks, after 1 week of trial i found this and it works <3

a1vinsmith profile image
Alvin Smith

Thank you, it's helped.

biina1 profile image

thanks (Y)