0

I’m using Virtualbox 4.3.30 and I’ve successfully set a virtual machine up with a host-only network to work on DHCP with a non-static IP, but of course, for a virtual machine server, it’s essentially useless. So now, I’m trying to set up a virtual machine Linux server with access to the internet, and a host-only static IP. Host is Windows 8.1, guest is Ubuntu server.

VM config

I have two network devices, one for NAT, and one host-only set to adapter #3. The NAT allows for access to the internet which works. The host-only adapter doesn’t allow the host to access the virtual machine.

VirtualBox config

Host-only adapter #3 has DHCP disabled, an IP of 192.168.50.101, and a netmask of 255.255.255.0.

The VM system

After running:

sudo ifconfig eth1 192.168.50.101 netmask 255.255.255.0 up

…(from here then ifconfig reveals that eth1 (host-only) is connected to the IP address. On the virtual machine, if I do wget 192.168.50.101 it pulls down the default Nginx page on itself. From the host I’m able to ping the static IP address however in the browser, the IP address times out with the message Unable to connect.

Stuff I've tried!

I have also tried editing /etc/network/interfaces from here to no success.

What’s happening here? I’m guessing it can’t be a firewall issue as the host connects when the host-only is using DHCP and I can successfully ping from the host. It also looks like the browser's "cannot connect message" appears in the browser faster than a simple timeout.

Update:

I think I've hit on a bug - if I activate the DHCP in the network only adapter, and set the lower and upper to the same ip address, it seems the browser can all of a sudden allow the network to occur and succeeds.

  • Please edit your question: What is your host OS? Also it might help if you could post the actual configuration of /etc/network/interface as well as the actual output of ifconfig. – JakeGould Oct 9 '15 at 16:38
  • Host os is specified, I've excluded any config for eth1 (host-only) from /etc/network/interface as that will only make it permanent, the eth1 up code is in the question though, and the relevant line from ifconfig is inet addr: 192.168.50.101 Bcast 192.168.55.255 Mask 255.255.255.0 – user3791372 Oct 9 '15 at 16:40
  • What is your host OS? Linux? I understand the guest OS is Linux, but I am still unclear. “It also looks like the cannot connect message appears in the browser faster than a simple timeout.” Fairly irrelevant point. Your web browser is not doing anything more unique than ping. Both items mean the host is not reachable. – JakeGould Oct 9 '15 at 16:45
  • Seriously, read the last line of the first paragraph. And like I wrote, ping can successfully ping the guest, but the browser can't reach it, though Nginx is up and succesfully running. – user3791372 Oct 9 '15 at 16:48
  • Okay, then this is an Nginx issue. Are you sure the Nginx config is set for networking and not just localhost connections? But I still feel your IP address settings might be a bigger factor here. Please read my latest edit to my answer. – JakeGould Oct 9 '15 at 16:59
0

You state that you set the following:

sudo ifconfig eth1 192.168.50.101 netmask 255.255.255.0 up

From all of my experience using VirtualBox, the guest OS works on a network in the 192.168.56.x range. So I would recommend using this command instead:

sudo ifconfig eth1 192.168.56.10 netmask 255.255.255.0 up

As for why I am choosing 192.168.56.10—instead of 192.168.56.101—in your comment to this answer you stated:

No, I can’t use 192.268.56.x as the default DHCP usually works within that range so will cause conflicts.

Well, the thing is with a netmask of 255.255.255.0 nothing but the last octet of the address will ever be passed to the larger network on the host. That’s what a netmask is. Further, if you look under “Preferences -> Network” from the VirtualBox application itself and then look under “Host-only Networks”, select that network—should be vboxnet0—and then click the edit icon and look under the DHCP server settings you will find these DHCP server settings:

  • Server Address: 192.168.56.100
  • Server Mask: 255.255.255.0
  • Lower Address Bound: 192.168.56.101
  • Upper Address Bound: 192.168.56.254

Note that DHCP is not taking up the whole range of IPs in 192.168.56.x; it simply starts at 192.168.56.100 for the DHCP server itself and then goes from 192.168.56.101 to 192.168.56.254. Which means IPs in the range of 192.168.56.2 to 192.168.56.99 are free for static use. Note that I left out 192.168.56.1 since that is the VirtualBox router IP address that connects the host OS to the guest OS.

And then to make the change permanent, add a network interface to /etc/network/interfaces like this. Open up the /etc/network/interfaces file:

sudo nano /etc/network/interfaces

And then when all that is tested, done and working as expected you can add—or adjust—the interface details like this:

# The local hostmachine access interface.
auto eth1
iface eth1 inet static
address 192.168.56.100
netmask 255.255.255.0
  • No, I can't use 192.268.56.xxx as the default DHCP usually works within that range so will cause conflicts, and this is no different to what I already have. – user3791372 Oct 9 '15 at 16:45
  • 1
    @user3791372 Check my edit to the answer. DHCP is not the full 192.268.56.x range. And the 255.255.255.0 netmask will not allow you to set a subnet other than something in the 192.268.56.x range. Just use an IP from 192.168.56.2 to 192.168.56.99 for a static address and there is no conflict. – JakeGould Oct 9 '15 at 16:56
  • Nope, not working – user3791372 Oct 9 '15 at 17:25
  • Ping responds, on the host, ipconfig shows the network adapter and the correct ip address, on the guest, eth1 is showing the correct inet address, but it's as if windows doesn't connect the virtualbox adapter to the actual machine (so it responds to pings, but nothing else) – user3791372 Oct 9 '15 at 18:54

protected by JakeGould Oct 17 '15 at 14:54

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.