Ubuntu – Connecting to a VirtualBox machine from the host, using an ip address

macbooknat;ubuntu servervirtualbox

In a macbook host, I run VirtualBox having a guest ubuntu server, with a NAT network setting.
In the virtual machine application "Parallels", I would get on the host an IP address of the guest, to which I could later set hostnames and access it directly.

However, I couldn't find a way to accomplish this using VirtualBox.
The only solution VirtualBox has for me, is to set port forwarding, and access "localhost" with these ports.

How can I have the desired behavior set up, without having to change to a bridged network settings, and expose my guest computer to the network my host computer is connected to ?

Thanks.

Best Answer

Well, I don't like answering my own questions, but I found a good answer in another question here, and I thought I'll share:

I was looking for an easy way to work with the virtual machine.
Since creating un orthodox ports (I couldn't forward port 80 of the host to port 80 of the guest, since VirtualBox doesn't allow that yet) is not an easy and comfortable way I couldn't accept any answer that said to do that, as it's not what I asked for.

So one of the answers I found in the list here to the right, said I can just create not one, but TWO network interfaces in VirtualBox for the relevant virtual machine, and then I would have one (NAT) for the host to access the VM, and another (Host-Only) for the VM to access the internet.
This way:

  • preserves the guest machine security as it's not on the same network as the host
  • gives me the ability to create a hostname for the guest ip, on my host machine - for easy access, without any need to use port forwarding from the host to the guest
  • and - gives me access to the internet for the guest machine

Since I tried different options, I had to manually setup the interfaces on the guest ubuntu server machine.
It made me encounter some problems which were pretty annoying so I thought I share one of them:
Make the first interface (eth0) the host-only interface (the one for connecting between the host and the guest), and the second interface (eth1) the NAT interface.
If you won't do so, you might have a problem with the guest machine trying to access the internet using the Host-only interface.
This issue might have been caused by something completely different, and the order may not have any relation to it, but that's what happened to me, so I share with anyone who reads this, in case you encounter such a problem.

Thank you for helping out!

EDIT: Just saw @Goyuix posted a link to the question that helped me out as well. Thanks @Goyuix.

Related Question