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 192.168.99.99
ipv4 network mask 255.255.255.0
DHCP server checked
Server address 192.168.99.100
Server mask 255.255.255.0
Lower address bound 192.168.99.101
Upper address bound 192.168.99.254
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
Adapter2
NAT
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
address 192.168.99.100
netmask 255.255.255.0
# 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.
Top comments (3)
Thanks, after 1 week of trial i found this and it works <3
Thank you, it's helped.
thanks (Y)