*Edit* Make virtualbox host only network bidirectional

nat;networkingvirtualbox

I have a virtualbox setup with both the host and VM OS as Windows 7. The host and the VM are both connected to the network but have different network IPs.

ipconfig on host (including only those adapters that show as connected):

Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::5019:de7c:51c0:f4f3%11
   IPv4 Address. . . . . . . . . . . : 192.168.43.121
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.43.1

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::cab:cd07:1f1b:79c3%17
   IPv4 Address. . . . . . . . . . . : 192.168.56.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

On the VM:

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::b941:4a97:86ff:b28c%11
   IPv4 Address. . . . . . . . . . . : 10.0.2.15
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.0.2.2

I would have expected a VirtualBox NAT adapter on the host but there isn't one and that the network on both to be the same but they are completely different. How can I connect to the Virtual Machine from the host?

Edit: It seems there was a gap in my understanding, NAT adapter cannot be accessed from the host to guest, it is internal to virtualbox(however I am not sure of this). I added a host only adapter and now I can access the guest from the host but not from the guest to host. How do I make that work?

Best Answer

Update: You have configured the VMs network interface on 10.0.2.15 but your virtual network interface of the ohst in on 192.168.56.1. They are not on the same network, thus can talk. See updated instruction under 1. for instructions.


Seems like you have run into the virtual networking jungle. It can be quite confusing. So let me make things a bit clearer for you:

  1. Host Only Network: for communication between virtual machines and your host. A new virtual network interface is created for your host, which has a its own addresse. Which means unless you make a service listen on the address it will not be reachable. Add a new host only network under Preferences>Networks>Host Only Networks. Pay attention to the following: the address you enter is the address of your host in this network not the network address (It will accept eg. 172.16.0.0 but this will break things). Configure the DHCP settings correctly, they are not automatically updated if you change the address of your virtual network adapter. It will happiely hand out 192.168.56.x configurations to all even if you have a different address configured. If you configure the VMs in this network manually, make sure they are on the same network as the virtual network interface of your host.

  2. NAT connects your virtual machine to the internet only. This hooks into the nating table of your network interface. This is why WLAN adapters and NAT networking on guest are trouble on Linux. Your host and guest share the same IP if look at from outside

  3. NAT networks: same as 2 but all the VMs connected to the same NAT network can talk. From the outside all VMs appear under the same address as your host, whilst having distinct addresses on the NAT network

  4. Bridged this hooks into the packet filtering and forwarding tables of your physical interface. All connected VMs get their own address on the same network as the host. From the out side the appear as separate devices each.

  5. Internal should be self explenatory

While picking the right network type it is important to configure the network settings on the guest properly so they have the proper IP, netmask, default gateway, routes and DNS settings for your applied scenario.

Further information can be found on Chapter 6. Virtual networking of the virtual box documentation. Its quite a tangle of Layer 2, Layer 3 and virtualisation features. One funny thing you can do is setting up tow host only networks with a firewall between them, filtering traffic, that then gets routed via a secondary route through your host system. Then tear your hair out for days, wondering why your firewall rules aren't working.

Related Question