Configuring VirtualBox host only networking: OSX host, Ubuntu guest

Posted by Greg K on Super User See other posts from Super User or by Greg K
Published on 2010-06-13T15:38:47Z Indexed on 2010/06/13 15:43 UTC
Read the original article Hit count: 1317

I have a Ubuntu guest configured with two interfaces, eth0 is using NAT and works fine, I can access the net.

The second interface eth1 is set to host only networking and VirtualBox has created a vboxnet0 virtual adapter on the host.

I've configured vboxnet0 in VirtualBox adapter settings with the following:

ip 192.168.21.20
subnet 255.255.255.0

Once the VM guest is running, ifconfig on OSX has vboxnet0 setup as:

vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:00 
    inet 192.168.21.20 netmask 0xffffff00 broadcast 192.168.21.255

In the guest, eth0 is set to use DHCP, I've statically assigned eth1 to 192.168.21.20 (is this a mistake?):

auto eth1
iface eth1 inet static
    address 192.168.21.20
    netmask 255.255.255.0
    network 192.168.21.0
    broadcast 192.168.21.255
    gateway 192.168.21.1

There is no device on 192.168.21.1 - what should I set my gateway to?

In the guest the routes look like so:

Destination    Gateway       Genmask        Flags Metric   Ref  Use  Iface
192.168.21.0   *             255.255.255.0  U     0        0    0    eth1
10.0.2.0       *             255.255.255.0  U     0        0    0    eth0
default        10.0.2.2      0.0.0.0        UG    100      0    0    eth0
default        192.168.21.1  0.0.0.0        UG    100      0    0    eth1

Route table on OSX:

$ netstat -nr
Routing tables

Internet:
Destination        Gateway          Flags      Refs      Use    Netif Expire
default            10.77.36.1       UGSc         28        0      en1
10.77.36/22        link#5           UCS           5        0      en1
10.77.39.38        127.0.0.1        UHS           1     2236      lo0
10.77.39.255       link#5           UHLWbI        1       66      en1
127                127.0.0.1        UCS           0        0      lo0
127.0.0.1          127.0.0.1        UH            1     8642      lo0
169.254            link#5           UCS           0        0      en1
192.168.21         link#7           UC            2        0  vboxnet
192.168.21.20      a:0:27:0:0:0     UHLWI         0        4      lo0
192.168.21.255     link#7           UHLWbI        2       64  vboxnet

I can't SSH from the host to the guest (I used to be able to when the VM was configured with a bridged connection):

$ ssh 192.168.21.20
ssh: connect to host 192.168.21.20 port 22: Connection refused

What have I done wrong here? TIA

© Super User or respective owner

Related posts about osx

Related posts about ubuntu