Nathan Beck
Nathan Beck

Reputation: 1191

Connect to VirtualBox localhost from a Mac host

I am running a .NET server running on localhost in a virtual box VM. I would like to access the VM localhost from a browser in my mac - I am developing a new javascript client for the project and would prefer to do so on my mac.

There are tons of answers about doing the opposite of the above (that is, connecting to the mac localhost from the VM) but I can't find a good answer about connecting to the VM localhost from the host.

Mac uses 10.1.10.173

$ ifconfig
--> inet 10.1.10.173 ...

VM uses 10.0.3.15 (found in Network Settings)

I have attempted using a Bridged Network adapter and NAT with Port Forwarding. There must be a way to do this - any thoughts?

Upvotes: 4

Views: 7239

Answers (1)

Nathan Beck
Nathan Beck

Reputation: 1191

Adding a (properly configured) port forwarding rule solved this issue.

VM uses IP 10.0.2.15 and IIS uses port 80 to serve my .NET API. Set up the new rule as follows:

VM Settings > Network > Adapter 1

Set as NAT and go into Advanced and click Port Forwarding. Add a new rule to forward port 80 from the VM to port 8000 (or whatever port number you want) on the mac.

Name     Protocol  Host IP  Host Port   Guest IP  Guest Port
Rule 1     TCP    127.0.0.1    8000     10.0.2.15     80

I can now interface with app on the VM from my mac using localhost:8000/the-app-name.

This was a useful read

Upvotes: 5

Related Questions