Configuring VirtualBox host only networking: OSX host, Ubuntu guest

25
2013-09
  • Greg K

    SOLVED: I got this working by reconfiguring the vbox network settings to 192.168.21.19 (in VirtualBox -> Preferences -> Network) and commenting the line specifying a gateway as it's not needed (no external access on the host only interface) as per this post.

    I can then SSH to 192.168.21.20 from OSX and connect to Ubuntu. I changed my /etc/fstab mounts to point to //192.168.21.19/


    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 (this was a mistake and the IPs clash between host and guest):

    auto eth1
    iface eth1 inet static
        address 192.168.21.20 (should be .19)
        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? (turns out a gateway is not needed as it's a HOST only interface). Net access is provided by the NAT adapter.

    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

  • Answers
  • Greg K

    I reconfigured the vboxnet0 virtual adapter IP on the host to 192.168.21.19 so it differs from the guests configuration of .20 - then they don't clash. See my updates in the post with more details about the solution.


  • Related Question

    networking - How to use CLEAR USB WiMax in Ubuntu (host) and Windows XP (guest) using VirtualBox
  • Questioner

    I'm trying to use CLEAR Motorola WiMax USB in Ubuntu as there is no support for Linux as yet. I've installed Windows XP as guest in Ubuntu and the version I'm using is 3.2.2. USB is connecting fine in Windows XP but I can't use internet in Ubuntu. Can you please tell me how to do it. Here is the configuration that could help you guys. Thanks in advance.

    I'm using Two Network Adapters.

    Network
    Adapter 1:
    PCnet-FAST III (NAT)
    Adapter 2:
    PCnet-FAST III (Host-only adapter, 'vboxnet0')
    

    ipconfig [on Guest windowsXP]

    Windows IP Configuration
    Ethernet adapter Local Area Connection:  PCnet-FAST III (NAT)
    
            Connection-specific DNS Suffix  . :
            IP Address. . . . . . . . . . . . : 10.0.2.15
            Subnet Mask . . . . . . . . . . . : 255.255.255.0
            Default Gateway . . . . . . . . . : 10.0.2.2
    
    Ethernet adapter Local Area Connection 3: PCnet-FAST III (Host-only adapter, 'vboxnet0')
    
            Connection-specific DNS Suffix  . :
            IP Address. . . . . . . . . . . . : 192.168.56.101
            Subnet Mask . . . . . . . . . . . : 255.255.255.0
            Default Gateway . . . . . . . . . :
    
    Ethernet adapter Local Area Connection 2: 
    
            Connection-specific DNS Suffix  . : CLEAR Motorola USB
            IP Address. . . . . . . . . . . . : 10.168.242.33
            Subnet Mask . . . . . . . . . . . : 255.255.192.0
            Default Gateway . . . . . . . . . : 10.168.192.2
    

    IFCONFIG [on Host Ubuntu]

    (Ethernet) eth0      Link encap:Ethernet  HWaddr 00:14:22:b9:9d:76  
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
              Interrupt:16 
    
    eth1    (Wireless) Link encap:Ethernet  HWaddr 00:13:ce:f0:9b:0d  
              inet6 addr: fe80::213:ceff:fef0:9b0d/64 Scope:Link
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1 errors:0 dropped:5 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:84 (84.0 B)
              Interrupt:17 Base address:0xe000 Memory:dfcff000-dfcfffff 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:2292 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2292 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:171952 (171.9 KB)  TX bytes:171952 (171.9 KB)
    
    vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00  
              inet addr:192.168.56.1  Bcast:192.168.56.255  Mask:255.255.255.0
              inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:137 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:21174 (21.1 KB)
    

  • Related Answers
  • ta.speot.is

    You should enable ICS on the Windows XP box and set the network adapter for vboxnet0 to DHCP.

    The Windows XP guest has a DHCP server built-in for ICS. When your vboxnet0 adapter sends a DHCP request the guest should return the necessary configuration information (specifically default gateway) to allow Ubuntu to route traffic through it.

    I don't know why you have two adapters for the guest.