127.0.0.1和localhost有什么区别? [英] What is the difference between 127.0.0.1 and localhost

查看:277
本文介绍了127.0.0.1和localhost有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在 ... / hosts 中定义了以下内容:

  127.0.0.1 localhost 

如果有的话,使用 127.0.0.1 localhost 作为服务器名称,特别是当正在监听正在侦听连接的本地运行的进程时?

解决方案

嗯,最有可能的区别是你仍然要做一个实际的查找 code> localhost 某处。



如果您使用 127.0.0.1 那么(智能)软件将直接将其转换为IP地址并使用它。 gethostbyname 的一些实现将检测虚线格式(可能是等效的IPv6格式),而不是完全查找。



否则,该名称必须解决。并且不能保证您的主机文件实际上将被用于该分辨率(首先或全部),因此 localhost 可能会成为一个完全不同的 IP地址。



我的意思是,在某些系统上, code> hosts 文件可以绕过。 host.conf 文件控件这在Linux(和许多其他Unices)上。


Assuming the following is defined in .../hosts:

127.0.0.1 localhost

What, if any, are the actual differences between using 127.0.0.1 and localhost as the server name, especially when hitting processes running locally that are listening for connections?

解决方案

Well, the most likely difference is that you still have to do an actual lookup of localhost somewhere.

If you use 127.0.0.1, then (intelligent) software will just turn that directly into an IP address and use it. Some implementations of gethostbyname will detect the dotted format (and presumably the equivalent IPv6 format) and not do a lookup at all.

Otherwise, the name has to be resolved. And there's no guarantee that your hosts file will actually be used for that resolution (first, or at all) so localhost may become a totally different IP address.

By that I mean that, on some systems, a local hosts file can be bypassed. The host.conf file controls this on Linux (and many other Unices).

这篇关于127.0.0.1和localhost有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆