127.0.0.1,0.0.0.0和localhost有何不同? [英] How are 127.0.0.1, 0.0.0.0 and localhost different?

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

问题描述

我不明白这些术语与它们如何连接之间的区别。



我查看了计算机上的hosts文件,可以看到127.0.0.1和localhost已连接但不确定如何以及我不知道0.0.0.0适合哪里所有这些。



我已经看到了这个问题的其他答案,但我是一个新手,关于环回和元地址的其他答案不容易理解。

解决方案

是的,在您的本地系统上 localhost 确实转换为127.0 .0.1,它始终是您当前使用的机器的IP地址。例如,在您的计算机上访问127.0.0.1(或localhost)只会尝试打开与您自己的计算机的连接(如果您正在托管本地Web服务器,则非常有用)



<同时, 0.0.0.0 有不同的用途。在服务器或任何具有1个以上IP地址的计算机上,可以使用它来引用计算机使用的所有IP地址。例如,如果使用 serverSocket 创建一个简单的Java应用程序,则可能希望服务器套接字侦听所有服务器IP地址上的传入连接。然后,您将服务器套接字设置为侦听0.0.0.0。希望这有帮助!


I don't understand the difference between these terms and how they are connected.

I looked at a hosts file on my computer and could see that 127.0.0.1 and localhost are connected but not sure how and I don't know where 0.0.0.0 fits into all this.

I've seen other answers to this question but I'm a newbie and the other answers about loopbacks and meta-addresses weren't easy to follow.

解决方案

Yes, on your local system localhost does translate into 127.0.0.1, which will always be the IP address of the machine that you are currently using. For example, on your computer accessing 127.0.0.1 (or localhost) will just attempt to open a connection with your own computer (useful if you're hosting a local web server)

Meanwhile, 0.0.0.0 has a different use. On a server or any machine with more than 1 ip address, it can be used to refer to all of the IP addresses that the machine uses. For example, if you create a simple java application with a serverSocket, you may want the server socket to listen for incoming connections on all of the servers IP addresses. You would then set the server socket to listen on 0.0.0.0. Hope this helps!

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

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