本地ip地址和本地ip地址有什么区别?

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。...

本地ip地址和本地ip地址有什么区别? If you’re doing a lot of network tinkering, configuring LAN-based apps and server tools, or just curious, you’ve likely noticed that there’s a difference between the localhost the local IP address. Read on to learn the differences.

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户读者Diogo想知道为什么ping命令对localhost和本地IP地址的处理方式不同,而从表面上看,它们似乎是相同的:

Using cmd and ping on Windows gave me the following results:

Pinging “localhost”:

007Ys3FFgy1gpg9rja02lj30fl06fglz

Pinging “192.168.0.10” (local IP address):

007Ys3FFgy1gpg9rkowluj30fl06fwez

Aren’t both situati*** exactly the same?

I mean, I’m pinging the same interface, the same machine and the same address. Why do I get such different results?

很明显,两者之间存在某种差异,但当你在两者之间切换时,到底发生了什么?

答案

超级用户贡献者Tom Wij**an对两者之间的细微差别提供了以下见解:

You are not pinging the same interface, without any physical interfaces you still have a “local host”.

Your localhost is used to refer to your computer from its “internal” IP, not from any “external” IPs of your computer. So, the ping packets don’t pass through any physical network interface; only through a virtual loop back interface which directly sends the packets from port to port without any physical hops.

You might still wonder why localhost is resolving to ::1, while traditionally we would expect it to resolve to the IPv4 address 127.0.0.1. Note that .localhost is traditionally a TLD (see RFC 2606) which points back to the loop back IP address (for IPv4, see RFC 3330, especially 127.0.0.0/8).

Looking up localhost using nslookup gives us:

nslookup localhost

... Name: localhost Addresses: ::1 127.0.0.1

Thus Windows prefers to use the IPv6 loop back IP address ::1 (see RFC 2373) as it is listed first.

Okay, so, where does it come from, let’s look at the hosts file.

type %WINDIR%\System32\Drivers\Etc\Hosts

... # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost ...

Hmm, we have to look at the DNS settings of Windows.

This KB article tells us about a setting that affects what Windows prefers, emphasized in bold:

  1. In Registry Editor, locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters
  2. Double-click DisabledComponents to modify the DisabledComponents entry.Note: If the DisabledComponents entry is unavailable, you must create it. To do this, follow these steps:
    1. In the Edit menu, point to New, and then click DWORD (32-bit) Value.
    2. Type DisabledComponents, and then press ENTER.
    3. Double-click DisabledComponents.
  3. Type any one of the following values in the Value data: field to configure the IPv6 protocol to the desired state, and then click OK:
    • Type 0 to enable all IPv6 components. (Windows default setting)
    • Type 0xffffffff to disable all IPv6 components, except the IPv6 loopback interface. This value also configures Windows to prefer using Internet Protocol version 4 (IPv4) over IPv6 by modifying entries in the prefix policy table. For more information, see Source and Destination Address Selection.
    • Type 0x20 to prefer IPv4 over IPv6 by modifying entries in the prefix policy table.
    • Type 0x10 to disable IPv6 on all nontunnel interfaces (on both LAN and Point-to-Point Protocol [PPP] interfaces).
    • Type 0x01 to disable IPv6 on all tunnel interfaces. These include Intra-Site Automatic Tunnel Addressing Protocol (ISATAP), 6to4, and Teredo.
    • Type 0x11 to disable all IPv6 interfaces except for the IPv6 loopback interface.
  4. Restart the computer for this setting to take effect.

What is this prefix policy table?

netsh interface ipv6 show prefixpolicies (or prefixpolicy on earlier versi***)

Precedence Label Prefix ---------- ----- -------------------------------- 50 0 ::1/128 45 13 fc00::/7 40 1 ::/0 10 4 ::ffff:0:0/96 7 14 2002::/16 5 5 2001::/32 1 11 fec0::/10 1 12 3ffe::/16 1 10 ::/96

This table decides what prefixes get precedence over other prefixes during DNS resolves.

Ah, so using that KB we could add entries here that denote that IPv4 has higher precedence than IPv6.

Note: There is no reason to override this behavior, unless you are experiencing compatibly problems. Changing this setting on our Windows Server broke our mail server, so it should be handled with care…

我们最喜欢的就是一个完整的、信息丰富的答案,并提供相关的支持文件。显然,localhost和localip地址是不同的实体,服务于不同的目的,现在我们都知道了原因。


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

 

  • 发表于 2021-04-12 00:27
  • 阅读 ( 261 )
  • 分类:互联网

你可能感兴趣的文章

ip地址(ip)和域名系统(dns)的区别

...中包含称为名称服务器的分支。当请求域名转换时,如果本地DNS名称服务器没有某个域的记录,它将向位于全球的13个根DNS服务器之一发送请求。根DNS服务器然后联系相应的tldns服务器(org、com等)以获取给定域名的缓存记录。...

  • 发布于 2020-10-25 09:15
  • 阅读 ( 221 )

网络101:以太网、局域网及其工作原理

...是其他的电脑不能作为回报。这怎么可能?这是因为您的本地网络被IPv4标准指定为“专用”。 ...

  • 发布于 2021-03-14 04:20
  • 阅读 ( 263 )

免费ip地理定位api是一个有价值的网站管理员工具

... 显示本地新闻。 突出显示与读者位置相关的信息(可能是与网站定位相对应的电视节目)。 针对读者提供特定于其位置的服务。 切...

  • 发布于 2021-03-20 15:06
  • 阅读 ( 195 )

如何找到android或iphone的ip地址

... 专用IP地址(或本地IP地址)标识您自己网络上的设备。一个网络上只有一个设备可以有一个特定的地址,但这个地址也可以在其他专用网络上使用。 ...

  • 发布于 2021-03-22 11:33
  • 阅读 ( 287 )

局域网和广域网在联网方面有什么区别?

...是一个所有连接的设备彼此接近的网络。它们都在一个“本地区”,因此得名。 ...

  • 发布于 2021-03-26 15:03
  • 阅读 ( 305 )

什么是127.0.1、localhost或环回地址?

... 127.0.0.1在IP地址中是特殊的。通常,IP地址对于本地网络和internet上的每台计算机都是唯一的。但是,127.0.0.1始终指向您当前使用的计算机,无论发生什么情况。 ...

  • 发布于 2021-03-30 20:02
  • 阅读 ( 612 )

如何使用ping命令测试网络

...来达到很好的效果。您可以测试您的计算机是否可以访问本地网络上的其他设备(如路由器),或者是否可以访问Internet上的设备。这可以帮助您确定网络问题是在本地网络上的某个地方,还是在其他地方。数据包返回到您的时...

  • 发布于 2021-04-05 07:03
  • 阅读 ( 238 )

如何查找任何设备的ip地址、mac地址和其他网络连接详细信息

...设备上找到这些信息。 在本教程中,我们将讨论如何在本地网络上查找设备的IP地址,通常称为专用IP地址。您的本地网络可能使用路由器连接到Internet。该路由器也将有一个公共IP地址一个在公共互联网上标识它的地址。要找...

  • 发布于 2021-04-07 20:34
  • 阅读 ( 178 )

如何找到你的私人和公共ip地址

网络上的每个设备都有一个只有本地网络上的其他设备才能看到的专用IP地址。但是您的ISP为您分配了一个公共IP地址,Internet上的其他设备可以看到该地址。下面是它的工作原理以及如何找到这些IP地址。 IP地址(或Internet协议...

  • 发布于 2021-04-08 06:44
  • 阅读 ( 194 )

如何在互联网上分享你的雷击游戏

如果你想通过互联网与朋友分享你的本地雷击游戏,这比仅仅按下一个按钮要复杂一些。让我们看看幕后的设置,你必须调整,以连接两个远程雷击机玩家在一起。 为什么要分享你的游戏? Minecraft是一个沙盒游戏,把你的朋...

  • 发布于 2021-04-08 10:41
  • 阅读 ( 195 )
Lily女神
Lily女神

0 篇文章

相关推荐