本地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
  • 閱讀 ( 69 )
  • 分類:網際網路

你可能感興趣的文章

ip地址(ip)和域名系統(dns)的區別

...中包含稱為名稱伺服器的分支。當請求域名轉換時,如果本地DNS名稱伺服器沒有某個域的記錄,它將向位於全球的13個根DNS伺服器之一發送請求。根DNS伺服器然後聯絡相應的tldns伺服器(org、com等)以獲取給定域名的快取記錄。...

  • 發佈於 2020-10-25 09:15
  • 閲讀 ( 49 )

瞭解ip和mac地址:它們有什麼好處?

...IP衝突,兩個或多個裝置共享同一IP地址。這主要發生在本地網路中。 ...

  • 發佈於 2021-03-13 11:32
  • 閲讀 ( 51 )

網路101:乙太網、區域網及其工作原理

...是其他的電腦不能作為回報。這怎麼可能?這是因為您的本地網路被IPv4標準指定為“專用”。 ...

  • 發佈於 2021-03-14 04:20
  • 閲讀 ( 51 )

如何將ip地址追蹤到pc&如何找到自己的ip地址

...主機名,隨後會顯示大量資訊,包括主機名、郵政編碼和本地時間。Geotool還使用Google地圖來描述起始IP地址的地理位置,以及顯示經緯度。 ...

  • 發佈於 2021-03-15 16:53
  • 閲讀 ( 61 )

免費ip地理定位api是一個有價值的網站管理員工具

... 顯示本地新聞。 突出顯示與讀者位置相關的資訊(可能是與網站定位相對應的電視節目)。 針對讀者提供特定於其位置的服務。 切...

  • 發佈於 2021-03-20 15:06
  • 閲讀 ( 36 )

如何找到android或iphone的ip地址

... 專用IP地址(或本地IP地址)標識您自己網路上的裝置。一個網路上只有一個裝置可以有一個特定的地址,但這個地址也可以在其他專用網路上使用。 ...

  • 發佈於 2021-03-22 11:33
  • 閲讀 ( 53 )

區域網和廣域網在聯網方面有什麼區別?

...是一個所有連線的裝置彼此接近的網路。它們都在一個“本地區”,因此得名。 ...

  • 發佈於 2021-03-26 15:03
  • 閲讀 ( 41 )

什麼是127.0.1、localhost或環回地址?

... 127.0.0.1在IP地址中是特殊的。通常,IP地址對於本地網路和internet上的每臺計算機都是唯一的。但是,127.0.0.1始終指向您當前使用的計算機,無論發生什麼情況。 ...

  • 發佈於 2021-03-30 20:02
  • 閲讀 ( 49 )

如何使用ping命令測試網路

...來達到很好的效果。您可以測試您的計算機是否可以訪問本地網路上的其他裝置(如路由器),或者是否可以訪問Internet上的裝置。這可以幫助您確定網路問題是在本地網路上的某個地方,還是在其他地方。資料包返回到您的時...

  • 發佈於 2021-04-05 07:03
  • 閲讀 ( 58 )

您可以在路由器的web介面中配置10個有用的選項

...數路由器都有基於web的配置頁,只要您與路由器在同一個本地網路上,就可以在web瀏覽器中訪問這些頁。要訪問路由器的web介面,首先需要找到路由器的本地IP地址。一般來說,您只需開啟網路連線的設定並查詢“預設閘道器”...

  • 發佈於 2021-04-07 10:23
  • 閲讀 ( 51 )
Lily女神
Lily女神

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦