今天遇到个奇怪的问题,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 IPv6

Prefix 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:

C:\>netsh interface ipv6 show prefixpolicies
Querying active state... Precedence Label Prefix
---------- ----- --------------------------------
50 0 ::1/128
40 1 ::/0
30 2 2002::/16
20 3 ::/96
10 4 ::ffff:0:0/96
5 5 2001::/32

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:

netsh interface ipv6 add prefixpolicy 2001:470::/32 3 6

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 IPv6

This solution is more generic, but more invasive and less standards-compliant. In the end, Windows will still modify the prefix policy table for you.

  • Open RegEdit, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters
  • Create DisabledComponents DWORD registry value, set its value to 20 (Hexadecimal). SeeMicrosoft KB 929852 for more info about this registry key, especially if DisabledComponentsalready exists on your system.
  • Reboot.

英语不是很好,最后对照着翻译软件大概看明白点。就是windows有个优先解析列表,当ipv6的优先级高于ipv4时,就会出现我今天遇到的情况(虽然会这样的原因依然没找到)。第一个办法是加一条优ipv4优先级高于ipv6的记录到优先解析表中,因为很多单词都看不懂,怕弄错参数,没敢用。我是用第二个办法解决的,就是修改注册表,方法如下(不懂英语的朋友就不用查了):

打开注册表,找到键 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters ,添加类型为DWORD 名字为 DisabledComponents 的项(已经有了的不用添加直接改值)。然后修改值为 ,值类型为16进制 。这样就完了,之后保存注册表,重启电脑。重新ping 下 localhost 试试看吧。

win10 localhost 解析为 ipv6地址 ::1 的解决办法的更多相关文章

  1. win10 localhost 解析为::1 的解决办法

    win10 localhost 解析为::1 的解决办法 学习了:https://blog.csdn.net/ambertian/article/details/70238020

  2. Advanced Installer 打包后,安装包在WIN10下重启后再次运行安装的解决办法

    原文:Advanced Installer 打包后,安装包在WIN10下重启后再次运行安装的解决办法 前几个月使用Advanced Installer 打包了一堆安装包,其中有使用默认主题的,也有根据 ...

  3. dedecms 模板文件不存在,无法解析文档的终极各种解决办法

    dedecms 模板文件不存在,无法解析文档"的终极各种解决办法 方法一:[此对应喜欢把模板文件使用".html"的格式,] /include/arc.archives. ...

  4. 全球免费公共 DNS 解析服务器 IP 地址列表推荐 (解决无法上网/加速/防劫持)

    除了宽带提供商的 DNS 以外,像阿里云.腾讯云.Google.百度.IBM.CNNIC 等一些有足够实力的大型互联网公司也非常慷慨地为公众提供了免费的 DNS 解析服务器.异次元这就搜集了全球范围内 ...

  5. 无法解析此远程名称: 'www.***.com' 解决办法 请求因 HTTP 状态 417 失败

    今天在做接口开发时,遇到了一个异常:无法解析此远程名称: 'www.***.com'.我的网站一直是运行正常的,从昨天开始出现异常,用户可以使用,但我的服务器怎么也无法实现对数据库的更新. 分析原因: ...

  6. 关于win10安装VisualSVN遇到的一个问题及解决办法

    问题:在win10系统中安装VisaulSVN遇到问题,错误提示:There is problem with this Windows Installer package. A DLL require ...

  7. 运行SparkStreaming的NetworkWordCount实例出错:Error connecting to localhost:9999 java.net.ConnectException: Connection refused 解决办法

    一.背景 首先按照Spark的官方文档来运行此实例,具体方法参见这里,当运行命令$ nc -lk 9999开启端口后,再运行命令$ ./bin/run-example streaming.Networ ...

  8. Win10卸载python总是提示error2503失败各种解决办法

    最近win10的电脑装了python的3.4,然后想卸载,就总是提示error 2053,类似于这种: 下面是我的坎坷解决之路: 1.网上说,任务管理器 --> 详细信息 --> expl ...

  9. PyTorch图文安装教程(Win10),含遇到的问题及解决办法

    PyTorch安装教程(Win10),含遇到的问题及解决办法 1. 环境准备 首先,打开PyTorch官网:https://pytorch.org/get-started/locally/ 向下可以看 ...

随机推荐

  1. Groovy解析xml并且注入Project,TestSuite,TestCase级别的custom properties

    import com.eviware.soapui.support.GroovyUtils import groovy.util.XmlParser def groovyUtils = new Gro ...

  2. Dotspatial 创建面状图层

    using DotSpatial.Controls;using DotSpatial.Data;using DotSpatial.Data.Forms;using DotSpatial.Plugins ...

  3. JavaScript之全局变量和隐式全局变量

    通过var创建的全局变量(任何函数之外的程序中创建)是不能被删除的. 无var创建的隐式全局变量(无视是否在函数中创建)是能被删除的.

  4. window下安装pip工具,再利用pip安装工具来安装其他的python包

    1.在安装pip前,请确认你window系统中已经安装好了python,和easy_install工具,如果系统安装成功,easy_install在目录C:\Python27\Scripts 下面,如 ...

  5. 安全协议系列(四)----SSL与TLS

    当今社会,电子商务大行其道,作为网络安全 infrastructure 之一的 -- SSL/TLS 协议的重要性已不用多说.OpenSSL 则是基于该协议的目前应用最广泛的开源实现,其影响之大,以至 ...

  6. MATLAB中白噪声的产生

    rand产生的是[0,1]上的均匀分布的随机序列randn产生均值为0,方差为1的高斯随机序列,也就是白噪声序列 rand产生的是均匀分布白噪声序列randn产生的是正态分布的白噪声序列 MATLAB ...

  7. How to upgrade Subversion on OSX

    How to upgrade Subversion on OSX http://andowebsit.es/blog/noteslog.com/post/how-to-upgrade-subversi ...

  8. fcitx 候选词出现奇怪的笔画

    原来fcitx还有笔画输入的功能,输入h出现一个横,s出现竖,p是撇,n是捺,z是折. 虽然很有意思,但是不实用,而且还会出现在第一页候选词中,影响输入,可以通过配置文件禁用掉: $ vim ~/.c ...

  9. ajax请求!

    ajax请求: var data ='{"useName":"'+name+'",}' $.ajax({ type:"post", url: ...

  10. 从零开始学习Node.js例子九 设置HTTP头

    server.js //basic server的配置文件 ; var server = require('./basicserver').createServer(); server.useFavI ...