1

My setup:

  • MacOS host (High Sierra 10.13.3)
  • Linux guest (Ubuntu 16.04)
  • Virtual Box 5.2.12
  • NAT networking

I need to talk from host to guest and from guest to internet.

The guest gets an IP address of 10.0.2.15 and gateway of 10.0.2.2. I can ping host from guest with no problem. Yet, I cannot ping guest from host:

PING 10.0.2.15 (10.0.2.15): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 Request timeout for icmp_seq 2 ...

10.0.2.2 address seems to be assigned to my host: I have an httpd server running on host - and if I navigate to 10.0.2.2 in a browser from guest, I get the host's site.

Looking at network configuration, I don't see any interfaces added by virtualbox:

host$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
OHC4: flags=0<> mtu 0
EHC36: flags=0<> mtu 0
EHC38: flags=0<> mtu 0
OHC6: flags=0<> mtu 0
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether xxxxx 
    inet6 fe80::1c34:9a51:ed93:3a5b%en1 prefixlen 64 secured scopeid 0x9 
    inet 10.37.37.37 netmask 0xffffff00 broadcast 10.37.37.255
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
    ether xxxxx
    media: autoselect
    status: inactive
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
    lladdr xxxxx
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect <full-duplex>
    status: inactive
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=b<RXCSUM,TXCSUM,VLAN_HWTAGGING>
    ether xxxxx
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect (none)
    status: inactive
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
    inet6 fe80::9a23:8dd9:bf4e:f69d%utun0 prefixlen 64 scopeid 0x8 
    nd6 options=201<PERFORMNUD,DAD>

and I don't see any routes to connect from host to guest:

host$ netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            10.37.37.1         UGSc           77       10     en1
10.37.37/24        link#9             UCS             3        0     en1
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              3   458010     lo0
169.254            link#9             UCS             0        0     en1
255.255.255.255/32 link#9             UCS             0        0     en1

Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::%utun0                    UGcI          utun0
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%utun0/64                         fe80::9a23:8dd9:bf4e:f69d%utun0 UcI           utun0
fe80::9a23:8dd9:bf4e:f69d%utun0         link#8                          UHLI            lo0
fe80::%en1/64                           link#9                          UCI             en1
fe80::1c34:9a51:ed93:3a5b%en1           f0:b4:79:1f:81:f0               UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%utun0/32                         fe80::9a23:8dd9:bf4e:f69d%utun0 UmCI          utun0
ff01::%en1/32                           link#9                          UmCI            en1
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%utun0/32                         fe80::9a23:8dd9:bf4e:f69d%utun0 UmCI          utun0
ff02::%en1/32                           link#9                          UmCI            en1

It's understandable that host can't talk to guest. The question is how can I make it do it?

0

2 Answers 2

2

I did figure it out eventually. The trick is to create a host-only network and then add two network interfaces in the guest - one for host-only network and the other one using NAT. Now the NAT interface allows the guest to access the internet and host-only interface allows two-way communication between the host and the guest.

1
0

I tried NAT Network and Internal Network with VirtualBox's DHCP Server and static IPs, but one or other I could not get my following requirements.

  • A VirtualBox network within required subnet
  • Use of VirtualBox's own internal DHCP Server
  • Within this network, few VMs with static IP, and others with DHCP
  • Host should be able to reach Guests via SSH, or whatever client
  • Most importantly, avoid Bridged Network, avoid exposing VirtualBox Network on my local net

Host-only Network was the life saver, and courtesy to @aleks-g's answer.

Here is my quickly documented step by step HOST setup.

# VBoxManage hostonlynet add --name=<NET_NAME> --netmask=255.255.255.0 --lower-ip=192.168.200.1 --upper-ip=192.168.200.254 --enable

Thats all, go ahead and create your VMs. Before you launch the VM, change network adapter type from NAT to Host-only, @screenshot

enter image description here

If your VM needs internet access from HOST, you can set network type NAT on Adapter 2, @screenshot

enter image description here

Next, I attempted to create dhcpserver and assigned static IPs as per VM name or MAC address

# VBoxManage dhcpserver add --netname <NET_NAME> --server-ip 192.168.0.1 --netmask 255.255.255.0 --lowerip 192.168.0.1 --upperip 192.168.0.254 --enable
# VBoxManage dhcpserver modify --netname <NET_NAME> --mac-address=<MAC_HERE> --fixed-address=192.168.0.101
# VBoxManage dhcpserver modify --netname <NET_NAME> --vm=<VM_NAME> --fixed-address=192.168.0.102
# VBoxManage list dhcpservers

With the last list command, DHCP server appeared with correct config, but VMs were not using this DHCP server and the docs didn't help much. I assume Host-only network has its own secret DHCP system, I deleted it with VBoxManage dhcpserver remove --network=<NET_NAME>, and had to manually assign static IPs on each VM, such as on Centos / Fedora vi|nano /etc/sysconfig/network-scripts/ifcfg-<DEVICE_NAME> and add

BOOTPROTO="none"
IPADDR="192.168.200.101"
PREFIX="24"
GATEWAY="192.168.200.254"
ONBOOT="yes"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .