-1

I run a web server locally on my Mac. I use Virtualbox to run various Windows guest OSes thanks to http://www.modern.ie/virtualization-tools The server on my host machine is running WordPress in a multi-site set-up and requires a host name in the request to serve up the correct site. IP address URLs won't work.

The Virtualbox network adapter is in NAT mode and I found the IP address of my host machine. I can get everything to work by editing the hosts file in the Windows guest OS. The entry looks something like this:

10.1.2.3 server.dev

Then in Windows if I browse to server.dev everything works as it should.

So my question is... Can I set it up so I don't need to edit the hosts file of my guest OS everytime the IP address of my host machine changes? Something like a reverse port forward so I could set a hosts file entry like so...

10.1.99.99 server.dev

and Virtualbox would listen for a request to 10.1.99.99 and change it to 127.0.0.1 ?

kingkool68
  • 243
  • 3
  • 10

3 Answers3

1

It turns out this is dead simple. I just needed to edit the Windows hosts file pointing

10.0.2.2 server.dev

Something about 10.0.2.2 being the default gateway for NAT connections? I gleamed the solution from this answer -> https://superuser.com/questions/144453/virtualbox-guest-os-accessing-local-server-on-host-os

kingkool68
  • 243
  • 3
  • 10
1

Your solution works but I'm rather surprised that it does, seems like it would cause problems if you happened to use 10.0.2/24 in your network somewhere. The alternative is to change your VirtualBox guests' network modes to Bridged, randomize their MAC addresses (if they're not already unique), and get them their own IPs on the network. At that point, they may live on your machine but they'll act just like someone else's PC in the office next door, so they provide more authentic test setups.

Drew Lanclos
  • 188
  • 1
  • 11
0

The sledgehammer approach would be to stand up a dns server that listens and serves dns information on the virtualbox only network (I'd recommend dnsmasq through homebrew.) That ultimately depends on how handy you are with DNS, or how much time you're willing to invest in figuring it out. I'd be happy to elaborate if there's any interest.

Stephan
  • 999
  • 7
  • 11
  • I tried figuring out how to set-up a DNS server on my local machine so I could test code served from my local machine to my phone. I think I looked at dnsmasq but couldn't get it to work. – kingkool68 Feb 05 '13 at 20:45