In Host-only networking mode, VirtualBox creates a virtual network interface called Host-only Ethernet Adapter on the host system. It is particularly useful when VMs not only want to talk to each other, but to the host system, too. Also, the traffic going through such an interface can be intercepted by binding a packet sniffer like Wireshark. Unlike other modes of networking supported, a static or dynamic IP can be set to this adapter.
A bug I stumbled upon in VirtualBox v4.3.20 running on Windows 7 Ultimate x64 is the IP of a freshly created host-only adapter getting reset every time it is configured manually. Surprisingly, I did not experience this bug on Windows 8.1 Enterprise x64 running the same version of VirtualBox. After quick googling, I discovered that bug#8796 and bug#11155 have already been reported. The video records the bug and the solution to it.
You can bind a static IP to the interface from Oracle VM VirtualBox Manager UI => File => Preferences => Network => Host-only Networks tab => Select the adapter => Click on the third button (Edit) on the right sidebar. Here, what you can see is, I have tried setting the IP 192.168.56.1 and netmask 255.255.255.0 to the host-only adapter several times. Every time I confirmed the IP-netmask pair by clicking ‘OK’ twice. Immediately after, when I reopened same dialog box, the IP and netmask get set to some random value.
To solve this issue, you need to set the adapter to obtain its IP address dynamically.
Navigate to Windows 7 Start Menu => Network => Network and Sharing Center => Change Adapter Settings => Right click on the host-only adapter interface => Properties => Select ‘Internet Protocol Version 4 (TCP/IPv4)’ => Click on ‘Properties’ button => Select ‘Obtain IP address dynamically’ radio button => Click ‘OK’. Now, you can set the IP-netmask of the adapter from inside VirtualBox and it won’t get reset any more.
Oracle VirtualBox’s is a robust virtualization solution and pretty much self-complete. So far, most probably you have used its built-in networking support without worrying about setting up an external DHCP server, e.g. TFTPD32 to supply network parameters to dynamic guest interfaces. The virtual machine receives its network address and configuration on the private network from a DHCP server integrated into VirtualBox. The server can be managed using VBoxManage dhcpserver command from command line or from the GUI, too. So far, so good.
Built-in server is a basic one, yet sufficient to meet the need of most of the applications unless you are into some advanced stuffs, viz. you may want to pass a dhcpd-option to the DHCP client sitting inside VM guest. One workaround is to set the VM to use Host-Only Adapter, disable the built-in DHCP server and run an external one. Ideally, the solution should work out-of-the-box. Probably due to a bug in VirtualBox 4.3.10 (on both Windows 7 Professional x64), it does not. Essentially, even after disabling the built-in DHCP server (18.104.22.168) and running a TFTFD32 server bound to VirtualBox Host-Only adapter (192.168.56.1) on host network, Ubuntu VM still receives DHCP OFFER packets from 192.168.56.100, i.e. the built-one. Attached is a transcript of DHCP cycle as captured by Wireshark.
The workaround I found is as follows:
- Remove built-in Host-Only Ethernet Adapter from Oracle VM VirtualBox Manager UI => File => Preferences => Network => Host-Only Networks tab => Select the adapter to be removed => Click on the second button on the right sidebar => Confirm removal
- Add a new adapter by clicking on the first button on the right sidebar of the same page. If asked, browse VBoxNetAdp.sys driver. On my system, it is located at C:\Program Files\Oracle\VirtualBox\drivers\network\netadp.
- Set appropriate IP (here 192.168.56.1) and netmask (here 255.255.255.0) for the adapter by clicking the third button on the right sidebar of the same page. If you face the problem of IP and/or netmask getting reset, please refer to this post.
- Make sure built-in DHCP server bound to newly created interface is disabled from the ‘DHCP Server’ tab. ‘Enable Server’ check-box must be unchecked.
- Verify that built-in DHCP server not running from command line by issuing ‘VBoxManage list dhcpservers‘ command.
- Set appropriate parameters in TFTPD64 DHCP settings. Don’t forget to bind it to the IP (here 192.168.56.1) of the new adapter.
- Boot up VM and verify the IP assigned to the guest interface by running ifconfig ethX (X = appropriate interface number). Also, the DHCP server offering the lease can be identified by running cat /var/lib/dhcp/dhcp/dhclient.ethX.leases | grep dhcp-server-identifier (X = appropriate interface number) command.
- Verify the same from the MAC <=> IP binding as displayed by TFTP64 main console.