HOST can't connect to GUEST with NAT networking at Virtualbox but others

4

0

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

TonyY

Posted 2018-01-05T03:30:22.933

Reputation: 141

Are you talking about VirtualBox or VMWare? They are completely different softwares. – None – 2018-01-05T07:08:10.800

Why need NAT between VM and host ? It's not logical. – Overmind – 2018-01-05T07:17:27.660

@ThePirateBay In my opinion, these virtual platforms should have the same behavior with NAT mode. Does it depend on different softwares? – TonyY – 2018-01-05T07:33:00.323

@Overmind I just curious about I always use default mode(NAT) at VMware and Parallels, and I can use HOST to connect GUEST. When I change to use Virtualbox, it didn't work, then I must change to Bridged or Host-only mode. – TonyY – 2018-01-05T07:46:55.470

"Does it depend on different softwares?" - I can't tell, as the VMWare is not open-source, but in general, yes, software can change NAT behavior. Therefore, the software you're using is an important information. – None – 2018-01-05T07:48:04.390

Of course it depends on different software. Different software could choose to implement different NAT behaviors. VirtualBox chose not to allow VM<=>Host communication over NAT. Other vendors chose differently. – jamesdlin – 2018-01-05T22:30:53.727

Answers

6

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).

Byron Katz

Posted 2018-01-05T03:30:22.933

Reputation: 161

1after you add that rule you need to restart VirtualBox (and thus your VM) - virtualbox should then be listening on port 2222 and you connect to your guest via your hosts IP, not the guest IP e.g. 192.168.1.1:2222 (not 10.0.2.4:2222 ! ) – wal – 2019-06-22T12:01:12.387

see also this image of the port forwarding (which was rejected as an edit to this answer by the nasty powers-that-be)

– wal – 2019-06-22T13:55:55.687

2

I know this is old, but the topic is relevant still, and I don't think I've seen this response yet, so here goes... I came to this thread with the same question. Then 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.

Alex S

Posted 2018-01-05T03:30:22.933

Reputation: 21

I confirm this works on VirtualBox 5.2.20 with a CentOS 6 and Windows 7 VM (testing old IEs). As long as the adapters are on the same named "Host-only Adapter", it should just work. – spyle – 2020-01-09T21:20:06.713

No luck for me with VirtualBox for MacOS and Ubuntu Bionic guest. The guest is given an IP address via DHCP in the range 192.168.56.0/24, but there is no way to reach this network from the host. There is no way to edit host-only networks in the preferences pane. – Graham Leggett – 2020-01-14T21:23:06.097