So here's my environment: I'm running Fedora on my laptop, with Apache, PHP, MySQL, Postgres and Ruby on Rails for my web development work. I then use VirtualBox to install a Windows XP virtual machine for browser compatibility testing.
Problem: How do I get my XP virtual machine (the guest) to see my Fedora's localhost (the host)?
I searched around, as you usually do when you encounter a problem, and their suggestion was to modify the guest's hosts file with your IP. However, without a static IP, and one being issued to me willy nilly by the DHCP server, that wasn't quite so acceptable. I'd have to change my hosts file every time I reconnected to the network. Ick.
I popped into #vbox IRC channel and most gloriously was provided a solution.
As long as your virtual machine is using NAT for its network configuration (which is the default on VirtualBox), then you can use the guest's default gateway instead of your host's IP address. This is 10.0.2.2 in normal situations.
My virtual machine is running XP, so in its command line I can run 'ipconfig' to see what the default gateway is:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\username>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : example.com
IP Address. . . . . . . . . . . . : 10.0.2.15
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.0.2.2
C:\Documents and Settings\username>Now I can take that number and edit the hosts file located at c:\WINDOWS\system32\drivers\etc\hosts. I just have to append the following to the bottom of the file:
10.0.2.2 ceardach.dev
10.0.2.2 kmgallery.devNote: Why .dev?
I use VirtualHosts in apache to serve multiple domains. To do so, I need to use more than just 127.0.0.1 or localhost for domains. So, I edit the hosts file to have .dev versions of my domains. Using the .dev TLD means I won't have any conflicts with real domains.






I do "nothing" on my system.
I install virtualbox, install winxp for virtual machine. Then in my IE i type the IP of the host. And things are ok. I don't have to custom the xp
Am i wrong?
kyanh, connecting to your host via IP will only allow you to connect to one website (you could have each as a sub folder of the main, but they're effectively all connected). Utilizing VirtualHosts allows you to have one IP serve multiple websites by accessing each from a domain name instead of the IP directly.
Editing your hosts file allows you to use custom created domain names that point towards your local computer. For example, I use "ceardach.dev" and "kmgallery.dev" for my websites.
This method allows you to "set it and forget it." If you're working on one website, you won't have to check your IP address every time you reconnect to the DHCP server, and when using multiple websites each can have their own unique domain to connect to.
Kathleen,
I'm using ubuntu as my host OS running apache and windows xp as the guest OS.
Accessing 10.0.2.2 from xp worked and pointed to the localhost of ubuntu.
My question is.. because apache is serving several virtualhosts on ubuntu, how do i make it so that xp points to the relevant apache virtualhosts address?
I followed your instructions, eg. putting "10.0.2.2 test.com" to the xp hosts file.
But, test.com still points to the localhost of ubuntu, even though i set it as a virtualhost..
Nevermind, it was an error in my part, hehe..