3

I have installed Windows XP and I want to override localhost from 127.0.0.1 to another address. I have edited ../windows/system32/drivers/etc/hosts, however ping localhost still get response from 127.0.0.1. How can I change it indeed?

6
  • 2
    I am sure you don't want that. This sounds like trouble, problems and pain.
    – glglgl
    Oct 23, 2013 at 7:12
  • Explain why you would want to do this. Oct 23, 2013 at 7:13
  • While editing hosts check out comment "localhost name resolution is handled within DNS itself." which tells you can't use hosts for that. I don't believe there is an easy way to redirect localhost (and agree with @glglgl that it likely will lead to strange behavior). Oct 23, 2013 at 7:15
  • Well, I installed Windows XP in a virtual machine. In host machine I run a web server. I want to access from vm in the same way as from the host machine.
    – ashim
    Oct 23, 2013 at 7:16
  • So what stops you from using host's machine name instead of localhost? Oct 23, 2013 at 7:17

3 Answers 3

5

This is snippet from Windows hosts file:

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

In other words, handling of localhost is hard-coded into Windows DNS stack, and your attempts to override that will be ignored.

3

Late answer, for reference. It is useful to access a host on localhost from within a VM, so the configuration does not need modification. The trick with hosts file worked in Windows 7, but failed on both XP and Windows 8. If you have specific ports you want to forward you can do that with netsh. Run a cmd prompt as Administrator, then:

For Windows XP first install ipv6:

netsh int ipv6 install

To add a forwarded port:

netsh interface portproxy add v4tov4 80 192.168.1.123

All traffic to localhost on port 80 will now be forwarded to 192.168.1.123.

1
  • This is the best answer! Jun 14, 2021 at 7:09
0

In order to resolve your problem, you could run a small server redirection program in your VM which upon an incoming connection contacts the host on the same port and feeds the data between these two sockets.

Imagine something like xinetd, listening on port 80 and executing netcat hostmachine 80 or so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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