Windows下设置DNS偏好 ipv4 > ipv6

某些站点未设置ipv6 ELB与DNS之间的映射,虽然google,facebook等互联网巨头均已支持ipv6, 此时,若本地客户机器设置的ipv6 DNS 偏好高于ipv4,将会导致站点无法访问,即使可以访问,也可能是延迟很高。本文提供了一个solution解决了此类问题。

若设置了ipv6偏好高于ipv4,敲入ping命令,可见如下:

C:\> ping www.google.com
 
 Pinging www.l.google.com [2001:4860:8005::68] with 32 bytes of data:
 Reply from 2001:4860:8005::68: time=85ms
 Reply from 2001:4860:8005::68: time=84ms
 Reply from 2001:4860:8005::68: time=112ms
 Reply from 2001:4860:8005::68: time=86ms
 
 Ping statistics for 2001:4860:8005::68:
     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
 Approximate round trip times in milli-seconds:
     Minimum = 84ms, Maximum = 112ms, Average = 91ms

若设置了ipv4偏好高于ipv6,此时可见是这样的:

C:\> ping www.google.com
 
 Pinging www.l.google.com [173.194.79.103] with 32 bytes of data:
 Reply from 173.194.79.103: bytes=32 time=28ms TTL=48
 Reply from 173.194.79.103: bytes=32 time=28ms TTL=48
 Reply from 173.194.79.103: bytes=32 time=55ms TTL=46
 Reply from 173.194.79.103: bytes=32 time=29ms TTL=46
 
 Ping statistics for 173.194.79.103:
     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
 Approximate round trip times in milli-seconds:
     Minimum = 28ms, Maximum = 55ms, Average = 35ms

那如何解决上述的问题呢?

Solution: 设置一条prefix policy 让ipv4的地址偏好高于ipv6

我们来看下default的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

Precedence代表偏好值,越大表示将以ipv6来解析。

接下来我们可以设置一条policy来指定某服务器的地址,强制以ipv4的方式来解析,比如某Server的ipv6地址为

2001:268:fd07:4::1,我们即可设置以下的policy。

netsh interface ipv6 add prefixpolicy 2001:268:fd07:4::1/128 3 6

2001:268:fd07:4::1/128表示ipv6地址,3表示precedence值,6表示label

这样,当遇到此ip时将会去直接优先采用ipv4去连接。over.


你可能感兴趣的:(Windows下设置DNS偏好 ipv4 > ipv6)