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.

user3791372
  • 111
  • 1
  • 11
  • 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`. – Giacomo1968 Oct 09 '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 09 '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. – Giacomo1968 Oct 09 '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 09 '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. – Giacomo1968 Oct 09 '15 at 16:59
  • Not an nginx issue as I also have gogs on the server which also does not receive connections on the static ip, but does if the host-only device is set to use the dhcp wtih a different adaptor. – user3791372 Oct 09 '15 at 17:25
  • So these network settings you are attempting… Are they in any way connected to the DHCP settings? Because honestly I’m not too sure how you have 3 interfaces and it works with DHCP but won’t with a static IP. If you set the static to be exactly like the DHCP you should be fine. And if you are worried about a DHCP address being used, then just shift it into the `192.168.x.2` to `192.168.x.99` range. – Giacomo1968 Oct 09 '15 at 18:14
  • I'm confused myself, I can ping whatever IP address I set on the static, but the browser won't connect to either Nginx or gogs, though will on the DHCP adapter (even when only two adapters are enabled at one, the Nat and DHCP host-only, or NAT and static host-only) - it's as if the static adapter is not accepting connections, but is only responding to pings – user3791372 Oct 09 '15 at 18:33
  • Can you perhaps provide details on the other two adapters? This is why I asked you to post the output of `ifconfig` to your question. Without that you are making it harder for the rest of us to understand your setup. – Giacomo1968 Oct 09 '15 at 19:11
  • the other adapter is bog standard nat. i've deleted the additional host-only adapter – user3791372 Oct 09 '15 at 19:18
  • Is there a reason you are avoiding posting the full output of `ifconfig`? The reality—as I am now saying again—is you are making it almost impossible for anyone to help you by not doing this. – Giacomo1968 Oct 09 '15 at 19:20

1 Answers1

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
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
  • 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 09 '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. – Giacomo1968 Oct 09 '15 at 16:56
  • Nope, not working – user3791372 Oct 09 '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 09 '15 at 18:54