24

It confuses me about NAT networking, but I can use VMware and Parallels Desktop to do that.

I knew NAT how it works, just need an explain about this situation.

The following is from official documents. Why HOST can't connect GUEST with NAT. enter image description here

ivan_pozdeev
  • 1,973
TonyY
  • 341

6 Answers6

27

If you want to connect to the guest machine from the host, using NAT Network:

First, create a NAT Network - create the network in the VirtualBox Manager, File -> Preferences -> Network, and give it a name.

Assign that named NAT Network to each of the guest machines in their Network configurations in VirtualBox.

Make a note of what IP address is assigned to your guest machines when you run them. It will be something like 10.0.2.15 or 10.0.2.4. In Posix systems, run "ifconfig" and see what ip addresses show up for em0. Make a record of which address goes to which guest machine.

Edit the NAT Network's port forwarding. In VirtualBox manager, go to File -> Preferences -> Network and click the edit button for the NAT Network you are using. Click on Port Forwarding. Add rules that forward ports on your host machine to ip address + port on the guests (You don't need to set the IP address for your host machine, that's optional).

19

I thought about it for a bit and realized an ideal solution that is easy to implement.

Add a second interface!!

One is the NAT interface for the VM to talk to the Internet. The other is a host-only interface. In my case, I'm installing a CentOS guest OS. The new interface shows up, both get their IPs on the respective networks. The host-only doesn't establish a default route, so no conflicts. It just works. I access the guest OS openly from the host using the IP on the host-only network that is defined within VirtualBox.

StayOnTarget
  • 1,494
Alex S
  • 191
12

To connect from HOST to GUEST VM with NAT networking, just add a port forward.

After that, you can access the forwarded port like a local port:

ssh root@localhost

enter image description here

8

It seems the official documentation has been improved to make it clearer of which direction the communication occurs, as I discovered from this answer:

Overview of networking modes

SharpC
  • 623
0

Was bitten by this 2 years ago. For the sake of simplicity i wanted to have all my guests on the same subnet as the VirtualBox interface of the host, to SSH or VNC into any of them. And also have them see eachother, and access Internet (client-only).

As i have about 10 guest VMs for development, on a laptop host that frequently changes from a network to another, i couldn't use bridging (wanted to use fixed-IPs for all the guests for easy access from host).

NAT network was nearly perfect, except no communication between guests and host.

Host-only network was nearly perfect, except no internet access for the guests.

I eventually managed to get a working configuration with one minimal Debian VM acting as DNSmasq with two interfaces, and a bridge of those two interfaces. Well, until last week i just toggled off the virtualbox network interface because of conflict with another software, and when re-enabling it, host to guest access wouldn't work at all anymore.

After 2 hours managed to get back either internet access to guests, or guests access between them and not to the host.

Might maybe try as a last resort Host-Only for all guests, and the gateway VM doing NAT, albeit it'd be very ugly to have both two NATs daisy-chained, and the guests having different addresses between them and from the host.

0

It's hard to believe that after so many years this is still a limitation in VirtualBox and that there are still people who defend that it should remain this way. VMWare solves this in a simplistic way by simply using a NAT network with some adaptations.

The possible solution is to use a "host-only" network and make some adaptations (workarounds). The complete solution is here https://superuser.com/a/1238065/195840 .

By following the procedures in the link provided, your Guests will be able to have network communication in all the ways below...

Guest-A <-> Host
Guest-A <-> Guest-B
Guest-A -> Internet

Thanks!