将域名重定向到Localhost


13

我有一台Linux测试机,我想运行生产Web服务器的副本。这是一个旧版应用程序,不使用属性文件作为其服务器名称。在整个应用程序中,服务器名称是硬编码的(例如:打开与myServer.myCompany.com的连接)。

有什么Linux技巧可以用来将特定主机的所有请求重定向回localhost?我知道在Windows中可以将一个条目添加到hosts文件并将其重定向回localhost。我如何在Linux中做到这一点?

Answers:


21

将以下行添加到/ etc / hosts中:

127.0.0.1 myserver.mycompany.com


如果有时通过http引用myserver.mycompany.com并用https引用其他时间,是否可以使用?即使使用不同的端口(超过80个)?
某人2010年

1
是的,它会的。您仅指定myserver.mycompany.com解析的IP。在该IP上连接到什么服务都没有关系。/ etc / hosts位于OSI第3层,服务是第4层构造。
baumgart 2010年

我正是在Debian 8 Jessie上做到的。它不起作用:host workflows.devbg.usreturn Host workflows.devbg.us not found: 3(NXDOMAIN)
鲍里斯·伯科夫

1
众所周知,nslookup / host不会查看/ etc / hosts。尝试ping通主机,它应该为您提供正确的IP。或尝试使用浏览器点击它。
baumgart
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.