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

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

问题描述

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

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

127.0.0.1 localhost

使用 127.0.0.1localhost 作为服务器名称之间的实际区别是什么(如果有的话),尤其是在访问本地运行的正在侦听连接的进程时?

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?

推荐答案

嗯,最可能的区别是你仍然需要在某处对 localhost 进行实际的查找.

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

如果您使用 127.0.0.1,那么(智能)软件会将其直接转换为 IP 地址并使用它.gethostbyname 的某些实现将检测点格式(并且大概是等效的 IPv6 格式)并且根本不进行查找.

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.

否则,必须解析名称.并且不能保证您的 hosts 文件实际上会被使用用于该分辨率(首先,或根本),因此 localhost 可能会变成一个完全不同的 IP 地址.

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.

我的意思是,在某些系统上,可以绕过本地 hosts 文件.host.conf 文件在 Linux(以及许多其他联合国).

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天全站免登陆