Skip to content

网络:17.0.0.1 和 localhost 以及 0.0.0.0 的区别

127.0.0.1

127.0.0.1 是一个 IPV4 地址,属于 本地回环地址

127 开头的都是回环地址,即(127.0.0.0 - 127.255.255.255

IPV6 地址表示为: ::1

在终端可以使用 ifconfig 命令查看到该地址

bash
ifconfig

#   lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
#	    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
#	    inet 127.0.0.1 netmask 0xff000000
#	    inet6 ::1 prefixlen 128
#	    inet6 fe80::1%lo0 prefixlen 64 sco
#
#   ...

localhost

是一个特殊的域名,默认指向 127.0.0.1

可以通过指令查看该域名映射关系,

bash
cat /etc/hosts

# --------
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

0.0.0.0

0.0.0.0 是一个特殊的保留地址,通常用于表示"未指定"或"任意"的意义

当服务绑定到 0.0.0.0 地址时,表示该服务会在所有可用的网络接口上监听传入的连接,允许从任何接口接收数据。

例如:服务器 listen 的是 0.0.0.0,那么此时用 127.0.0.1本机地址 都可以访问到服务。

Released under the MIT License.