Ubuntu – How to run Virtualbox on bridged and host-only networks

virtualbox

I wish to run VirtualBox with my Ubuntu laptop on the home network (so the desktop PC can access it through the router) and also be able to ssh into the VirtualBox from host on the go (different network or with no internet).

Previously, the only network adapter on the VB instance was a 'bridged connection' adapter. This allowed me to access the internet on the guest VB and for the other computers on the LAN + host to access it. However, whenever I took my laptop off the network, I could no longer access the guest from host.

I read that I needed to enable a host-only adapter to access it off the network and a NAT adapter is used to access the internet from guest.

My question is can I run a host-only adapter + a NAT adapter alongside a bridged network adapter in VirtualBox? I am confused what I would put inside /etc/hosts? Would I put both IP's (host-only and bridged) with the same servername in /etc/hosts?

Best Answer

Figured it out. I was following this tutorial and I was putting in eth1 instead of eth2. I had to use eth2 because host-only was 'adapter 3' in the VB settings-network (using VB's GUI). Now I am able to run both bridged and host-only!

For /etc/hosts: On the host machine I put: 'host-only-IP' 'servername' On the guest VB I put both the host-only and the bridged IP's with the same servername. Doesn't seem to cause an issue.

So to summarize; I have 3 adapters on the VB instance

  1. Bridged
  2. Nat
  3. Host-only.

I have the host file on my host machine configured to use the host-only IP and my desktop host file is configured to use the bridged IP address. This way I can take out my laptop off the network and still be able to ssh into my VirtualBox server without changing any settings. Then I can turn the NAT network adapter on and the VirtualBox can use my hosts network for the internet away from my home network.