Question on Virtual Box 4.1.8
So, i have Ubuntu 10.10 as host machine and Windows Xp as guest machine. On host machine there is tomcat with web app running on port 8888. When i am in guest machine i type in browser: and it works.
But my Something.html has links to javascript like src="http://localhost:8888/webApp/someScript.js and they obviously aren't working(because of "localhost" part).
The other problem is that i don't want to use relative path now, only absolute. Also i don't want to change localhost to Host Ip in my links
Maybe there is some solution, like port forwarding or network config of Virtual box, that i can type in my guest browser http://localhost:8888/Something.html

Thanks for any clues.

  • I have no idea if Windows uses 'localhost' for anything internally (I don't think it does - but could be wrong). If it doesn't what you can do is to map 'localhost' to (instead of the typical on your Windows guest. Edit %SystemRoot%\system32\drivers\etc\hosts and add/modify localhost. (On Linux this would definitely be a bad idea, but you might get away with it on Windows). – cyberx86 Mar 24 '12 at 12:26
  • 1
    Already tried. It doesn't work. Windows Xp always maps localhost to – IgorDiy Mar 24 '12 at 12:32

Your real problem is that you want to do things that doesn't make sense for any kind of web app that should serve anything outside it's machine: You need links that work without tricks on the client machine, either with relative paths where applicable or non-local hostnames.

Of course there is a workaround:

Simply install Putty on Windows and use it to create a port forwarding from port 8888 on your machine to port 8888 on You will find lots of links with Google that explains how this is done in Putty.

Afterwards, you can simply connect to localhost:8888 and stuff should work.

  • this is awesome. once the ssh connection is established, the tunnel just works in the browser. for my setup, i forwarded 8080 to localhost:8080, since I wanted the localhost on the guest machine to hit the localhost of the host machine. here's a good ref for putty tunneling - howto.ccs.neu.edu/howto/windows/ssh-port-tunneling-with-putty – chrismarx Jan 28 '15 at 21:39

If you manually add a hostname for the host in /etc/hosts (on the host) and in %systemroot%\system32\drivers\etc\hosts (on the guest), you can use that name in your code. And since both machine can resolve it it should work. As SvenW mentioned that's not the way one is supposed to solve it but should be fine for testing purposes.

Example of the hosts entry: webapphoster

...and then you can call the js:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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