今天遇到個奇怪的問題,localhost 訪問時提示 not found 404,但是有127.0.0.1可以訪問。最后找到原因,是因為 windows 把 localhost 解析為 ipv6 地址 ::1 而不是 127.0.0.1。查了hosts 把ipv6已經屏蔽了,127.0.0.1 localhost 也有,就是不能正常解析。百度查了半天無果,最后用科學上網法在google找到了解決辦法,為防止原貼丟失,轉貼至此(原貼地址:http://superuser.com/questions/436574/ipv4-vs-ipv6-priority-in-windows-7/436944#436944)。
文章內容:
Solution #1: Add a prefix policy to prefer IPv4 addresses over IPv6Prefix policy table is similar a routing table, it determines which IP addresses are preferred when making a connection. Note that higher precedence in prefix policies is represented by a lager "precedence" value, exactly opposite to routing table "cost" value. Default Windows prefix policy table:
Note that IPv6 addresses (::/0) are preferred over IPv4 addresses (::/96, ::ffff:0:0/96). We can create a policy that will make Hurricane Electric IPv6 tunnel less favourable than any IPv4 address:
2001:470::/32 is Hurricane Electric's prefix, 3 is a Precedence (very low) and 6 is a Label. I could have used a more generic prefix, but I wanted to make sure than if and when I get a direct IPv6 connectivity from an ISP, it will take precedence over IPv4. If you adapt this solution, you need to substitute an appropriate IPv6 prefix instead of my Hurricane Electric one. Solution #2: Tweak registry to make Windows always prefer IPv4 over IPv6This solution is more generic, but more invasive and less standards-compliant. In the end, Windows will still modify the prefix policy table for you.
|
英語不是很好,最后對照着翻譯軟件大概看明白點。就是windows有個優先解析列表,當ipv6的優先級高於ipv4時,就會出現我今天遇到的情況(雖然會這樣的原因依然沒找到)。第一個辦法是加一條優ipv4優先級高於ipv6的記錄到優先解析表中,因為很多單詞都看不懂,怕弄錯參數,沒敢用。我是用第二個辦法解決的,就是修改注冊表,方法如下(不懂英語的朋友就不用查了):
打開注冊表,找到鍵 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters ,添加類型為DWORD 名字為 DisabledComponents 的項(已經有了的不用添加直接改值)。然后修改值為 20,值類型為16進制 。這樣就完了,之后保存注冊表,重啟電腦。重新ping 下 localhost 試試看吧。