Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question

closed as off topic by Michael Hampton, mgorven, Scott Pack, Dave M, mdpc Feb 5 '13 at 2:48

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers 3

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 -> http://superuser.com/questions/144453/virtualbox-guest-os-accessing-local-server-on-host-os

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
    
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 5 '13 at 20:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.