5

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.

1
  • How can I have the desired behavior set up, without having to ... expose my guest computer to the network my host computer is connected to? Doesn't the desired behavior require that the two networks be connected? Bridged is probably your easiest solution.
    – heavyd
    Jan 8, 2011 at 17:35

2 Answers 2

4

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.

2

There are several networking choices when configuring a guest machine, it would be worth it to review the official document on Virtual Networking. Because you have ruled out bridged networking, your choice of the remaining modes really boils down to if you want your guest to have access to networks beyond the host (e.g. do you need internet access).

If you need internet access, your best choice is to use NAT networking as you have described. You will need to forward specific ports to through the VirtualBox NAT engine to access the services on your guest. There are a bunch of related questions here on SuperUser that cover it, but basically you would enter commands similar to these on the command line (this instructs the host to forward incoming connections on TCP 8080 to TCP 80 on the guest):

VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/Protocol" TCP
VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/GuestPort" 80
VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort" 8080

If the guest machine does not require access to the internet, you will be best off by using the "Host-only networking" model. This will bridge the guest adapter with a software based adapter on the host (typically in the 192.168.56.0/24 subnet). You will be able to access any services on the host or the guest without any additional configuration. Well, possibly allowing the traffic through any software firewalls you may have installed - but generally this "just works"™

You must log in to answer this question.

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