windows hosts文件可以重定向IP地址吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16855114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can the hosts file redirect an IP address?
提问by cja
I have cloned a Windows 2003 machine and put it on the same domain as the original.
我已经克隆了一台 Windows 2003 机器并将它放在与原始机器相同的域中。
I want to make sure that the clone never accesses the original. I want it to think it is the original. I don't want to exhaustively check the clone for everything that might reference the name or IP address of the original and change to the name or IP address of the clone.
我想确保克隆永远不会访问原始的。我希望它认为它是原始的。我不想彻底检查克隆中可能引用原始名称或 IP 地址并更改为克隆名称或 IP 地址的所有内容。
Will I get what I want if I add the following two lines to the hosts file on the clone?
如果我将以下两行添加到克隆的主机文件中,我会得到我想要的吗?
127.0.0.1 originalname #divert attempts to access the original machine
127.0.0.1 192.168.1.2 #divert attempts to access the original machine
originalname is the name of the original machine. 192.168.1.2 is the IP address of the original machine.
originalname 是原始机器的名称。192.168.1.2是原机的IP地址。
采纳答案by Gerric Chaplin
You first line should do the trick although you might want to add an additional short name to that entry.
尽管您可能想为该条目添加一个额外的短名称,但您的第一行应该可以解决问题。
Your second entry will never work. You can not redirect/mask an IP address with another IP address. The server should no longer think it should be resolved at 192.168.1.2 once you put the first line in place.
您的第二个条目将永远无法工作。您不能使用另一个 IP 地址重定向/屏蔽 IP 地址。一旦您将第一行放置到位,服务器不应再认为它应该在 192.168.1.2 处解析。
To be 100% sure you can always Flush the DNS cache for good measure. http://technet.microsoft.com/en-us/library/cc782459(v=ws.10).aspx
要 100% 确定您始终可以刷新 DNS 缓存以获得良好的衡量标准。http://technet.microsoft.com/en-us/library/cc782459(v=ws.10).aspx
This is worth reading and should explain the process of name resolution on Windows operating systems: http://support.microsoft.com/kb/172218.
这是值得一读的,应该解释 Windows 操作系统上的名称解析过程:http: //support.microsoft.com/kb/172218。
Hosts files can not redirect IP addresses. They can only redirect names/hosts to resolve to a different IP address.
主机文件不能重定向 IP 地址。他们只能重定向名称/主机以解析到不同的 IP 地址。