我已安装Windows XP,我想将localhost从127.0.0.1覆盖到另一个地址。我已编辑../windows/system32/drivers/etc/hosts
,但ping localhost
仍然可以从127.0.0.1获得回复。我怎么能改变呢?
答案 0 :(得分:5)
这是来自Windows主机文件的片段:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
换句话说,localhost的处理被硬编码到Windows DNS堆栈中,您的覆盖尝试将被忽略。
答案 1 :(得分:2)
迟到的答案,供参考。从VM中访问localhost上的主机很有用,因此不需要修改配置。
使用hosts文件的技巧在Windows 7中有效,但在XP和Windows 8上都失败了。如果你想转发特定的端口,你可以使用netsh做到这一点。以管理员身份运行cmd
提示,然后:
对于Windows XP,首先安装ipv6:
netsh int ipv6 install
添加转发端口:
netsh interface portproxy add v4tov4 80 192.168.1.123
端口80上localhost的所有流量现在都将转发到192.168.1.123。
答案 2 :(得分:0)
为了解决您的问题,您可以在VM中运行一个小型服务器重定向程序,该程序在传入连接上与同一端口上的主机联系并在这两个套接字之间提供数据。
想象一下像xinetd这样的东西,监听端口80并执行netcat hostmachine 80
左右。