How can I get virtualbox to run with a hosts-only adapter?

38

6

I'm trying to setup a Hosts-only Adapter so I can connect to it. It says that invalid settings detected and the name: drop-down isn't populated. What am I doing wrong and how can I rectify it?

My Host is and my guest is .

enter image description here

Kit Sunde

Posted 2012-05-27T15:02:42.113

Reputation: 2 171

Why are you using Host only Adapter, it's primarily for communication between hosts, use NAT instead – HackToHell – 2012-05-27T15:24:19.450

@HackToHell I'm using it so I can http into the guest OS. – Kit Sunde – 2012-05-27T15:32:02.670

By http, you mean run a web server in the guest, NAS will work, Host Only is not neeeded – HackToHell – 2012-05-27T15:33:05.443

1

@HackToHell I'd prefer not to do port forwarding and couple my local machine ports to the VM. I'd like to be able to access the VM on an IP I've assigned it, but not have to adapt to an external DHCP server. So I'm trying to go down this route: http://stackoverflow.com/a/2047646/29347

– Kit Sunde – 2012-05-27T15:48:35.900

9@HackToHell, Host Only is needed in a couple of scenarios which is why every VM provider offers it. This is not helpful input. – Rob Osborne – 2012-08-03T15:18:46.957

Answers

54

It seems like these adapters are added in Virtual Box -> preferences -> network.

enter image description here

Kit Sunde

Posted 2012-05-27T15:02:42.113

Reputation: 2 171

note: I've encountered situation where "preferences" menu item is not displayed. Restart virtual box if encountered and it should show up. – harschware – 2015-03-17T17:58:10.577

Actually, no restart needed. This happens when the "Oracle VM Virtual Manager" is not the foreground window. If your VM is the foreground window it will be missing from the "VirtualBox VM" menu. As of VBox 4.3.18 – harschware – 2015-03-17T18:15:00.797

After configuring this here and selecting it in the other dialog (as shown by the OP), you may still find that the network is disconnected by default -- so yet one more step is required (connect the network from the VirtualBox GUI). – nobar – 2017-11-08T17:06:11.957

For Virtualbox 6.X, I had to use File > Host Network Manager – Nyxynyx – 2020-01-11T00:56:15.587

3wow that did the trick! +1! – FLY – 2012-08-03T09:20:15.557

7wow indeed, who writes user interfaces like this? – Rob Osborne – 2012-08-03T15:13:47.817

wow somebody wants all vm to be accessible! that's why. – CppLearner – 2013-03-31T05:15:31.333

6

Since Virtualbox 5.2.xxx, the location to create a host-only network has now changed to File -> Host Network Manager...

Clicking on the Create button in the Host Network Manager window will create a host-only network called vboxnet0, which you can then use within the VM settings.

Rekovni

Posted 2012-05-27T15:02:42.113

Reputation: 163

4

In order to have bidirectional access please follow next steps ...

It's very important that after (Virtual Box -> Preferences -> Network -> vboxnet0) to configure your firewall.

  1. Allow routing (ip.forwarding)
  2. Allow NAT through fireall

OSX firewall sample

    # (I) Firewall config /etc/sysctl.conf
    sysctl -w net.inet.ip.forwarding=1 net.inet.ip.fw.enable=1
    sysctl -a net.inet.ip.forwarding net.inet.ip.fw.enable

    ipfw list
    ... shoud have ....
    net.inet.ip.forwarding=1
    net.inet.ip.fw.enable=1


    # (II) Enable nat access to /etc/pf.conf
    #============add your host-only vlan =================
    # this commented lines doesn't work after computer reboot
    #nat on en0 from vboxnet0:network -> (en0)
    #nat on en3 from vboxnet0:network -> (en3)
    # this will work in any situation
    nat on en0 from 10.1.100.0/24 to any -> (en0)
    nat on en3 from 10.1.100.0/24 to any -> (en3)        
    #==========================        

    # Reload pf
    pfctl -f /etc/pf.conf
    pfctl -e

Enjoy

myset

Posted 2012-05-27T15:02:42.113

Reputation: 241

I'm confused by this answer. Immediately after changing my VM network to Host-only adapter, I looked on OSX host for /etc/sysctl.conf but the file was not there. I checked ifconfig on the guest to see the new adapter present, but did not have an IP4 address. I checked for that file on CentOS6.6 guest and found it, found 'net.ipv4.ip_forward = 0'. set it to 1, saved file, and immediately a IPV4 address became available. I could use it to ssh to the VM from the host and another guest configured the same way. – harschware – 2015-03-17T18:19:59.077

0

You can do it command line (since the UI location is not consistent) like so: VBoxManage hostonlyif create. This will create a vboxnet0 interface ready for use.

Yann VR

Posted 2012-05-27T15:02:42.113

Reputation: 101