適用於:Windows,MacOS,Linux

快速答案: local-Host IP是 127.0.0.0.1 (ipv4)和:: 1 (ipv6)。 “ Localhost”是一個特殊的主機名,它總是循環回到您自己的設備。

“ localhost”

它指向機器上的環回接口,用於運行和測試應用程序和服務器。當應用程序連接到LocalHost或127.0.0.1時,該連接停留在設備內。

IPv4: 127.0.0.1 (the entire 127.0.0.0/8 block is reserved; most systems use.1) IPv6:::1

How to check localhost works

Windows

Open Command Prompt and run: ping localhost ping 127.0.0.1 To test IPv6: ping:: 1

Pro提示:在PowerShell中,測試本地服務端口(替換3000):

test-netConnection-computerName localhost-port-port-port-port 3000

macOS

macos

Open strong> terminal terminal and run:ping-c 4 local-c 4 local ping-cback-cback-c beback-c 4 127.1.1 perty; ifconfig lo0

Linux

Open Terminal and run: ping-c 4 localhost ping-c 4 127.0.0.1 ping-c 4::1 View the loopback interface: ip addr show lo

Common confusions, cleared up

0.0.0.0 vs 127.0.0.1: 0.0.0.0的意思是“所有IPv4地址/未指定”。綁定到0.0.0.0的服務器接受網絡的連接; 127.0.0.1僅本地。 local-Host vs 192.168.x.x: 192.168.x.x是您的LAN IP,可以通過同一網絡上的其他設備觸發; 127.0.0.1不是。 127.0.1.1您可能會在Linux上看到:一些發行版將其添加到機器主機名中。 Localhost仍應解決至127.0.0.1和:: 1。

在其中定義了“ localhost”

Windows主機文件: c:\ Windows \ system32 \ drivers \ etc \ etc hosts macos/linux主機文件文件:/etc/hosts
確保您有諸如:127.0.0.0.0.0.1 localhost forne forts forts forts: 你正在做的;不好的條目可能會破壞本地服務。

開發人員提示

使用localhost:port(例如,localhost:3000)到達本地服務器。 與 127.0.0.1 綁定,以供私人訪問;綁定到 0.0.0.0 (或::)允許網絡上的其他設備連接。 您不需要Internet訪問-Localhost脫機工作。

Categories: IT Info