How are 127.0.0.1, 0.0.0.0 and localhost different?

最后都变了- 提交于 2019-12-08 16:19:50

问题


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.


回答1:


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!




回答2:


Any address in the whole 127.0.0.0/8 block will loop sent traffic back inside the computer.

Localhost is normally set to 127.0.0.1, but it could be set on any address in the 127.0.0.0/8 block.

The 0.0.0.0 address really means any IPv4 address.



来源:https://stackoverflow.com/questions/38834434/how-are-127-0-0-1-0-0-0-0-and-localhost-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!