我在无法使用开关设备的办公室环境中遇到了最奇怪的行为。启用 IPv6 时,socket.gethostbyname() 失败,并且 socket.getaddrinfo() 在 10 秒的长时间超时后仅返回 IPv6 地址。如果我手动禁用 IPv6 并刷新租约,它们都会开始工作。
使用有线以太网的 MBP 上的最新 OS X Mountain Lion 10.8.2。我最近注意到您无法关闭 IPv6,只需设置为链接本地即可。您可以使用 networksetup 将其关闭,但这只会持续到重新启动。
关于如何追踪这一点的任何想法?我认为问题出在开关而不是我的机器上,但不知道下一步该往哪里看。
我的 v4 DHCP 服务设置为 8.8.8.8/8.8.4.4。
(nimbis)bschott@ironman:django-nimbis$ sudo dscacheutil -flushcache
(nimbis)bschott@ironman:django-nimbis$ host www.google.com
www.google.com has address 74.125.131.99
www.google.com has address 74.125.131.103
www.google.com has address 74.125.131.104
www.google.com has address 74.125.131.147
www.google.com has address 74.125.131.106
www.google.com has address 74.125.131.105
www.google.com has IPv6 address 2607:f8b0:400c:c03::63
这里 gethostbyname 失败并且 getaddrinfo 在长时间超时后返回。
(nimbis)bschott@ironman:django-nimbis$ sudo dscacheutil -flushcache
(nimbis)bschott@ironman:django-nimbis$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyname('www.google.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
>>> socket.getaddrinfo('www.google.com', 80)
[(30, 2, 17, '', ('2607:f8b0:400c:c03::63', 80, 0, 0)), (30, 1, 6, '', ('2607:f8b0:400c:c03::63', 80, 0, 0)), (30, 2, 17, '', ('2607:f8b0:400c:c03::63', 80, 0, 0)), (30, 1, 6, '', ('2607:f8b0:400c:c03::63', 80, 0, 0)), (30, 2, 17, '', ('2607:f8b0:400c:c03::93', 80, 0, 0)), (30, 1, 6, '', ('2607:f8b0:400c:c03::93', 80, 0, 0))]
>>> ^D
Ping 失败。
(nimbis)bschott@ironman:django-nimbis$ host www.google.com
www.google.com has address 173.194.75.103
www.google.com has address 173.194.75.99
www.google.com has address 173.194.75.104
www.google.com has address 173.194.75.106
www.google.com has address 173.194.75.105
www.google.com has address 173.194.75.147
www.google.com has IPv6 address 2607:f8b0:400c:c03::93
(nimbis)bschott@ironman:django-nimbis$ ping www.google.com
ping: cannot resolve www.google.com: Unknown host
关闭 IPV6:
(nimbis)bschott@ironman:django-nimbis$ sudo networksetup -setv6off Ethernet
(nimbis)bschott@ironman:django-nimbis$ sudo dscacheutil -flushcache
(nimbis)bschott@ironman:django-nimbis$ ping www.google.com
ping: cannot resolve www.google.com: Unknown host
(nimbis)bschott@ironman:django-nimbis$ host www.google.com
www.google.com has address 173.194.75.103
www.google.com has address 173.194.75.99
www.google.com has address 173.194.75.104
www.google.com has address 173.194.75.106
www.google.com has address 173.194.75.105
www.google.com has address 173.194.75.147
www.google.com has IPv6 address 2607:f8b0:400c:c03::68
强制 DHCP 租约更新,ping、gethostbyname、getaddrinfo 都可以正常工作。
(nimbis)bschott@ironman:django-nimbis$ ping www.google.com
PING www.google.com (173.194.75.103): 56 data bytes
64 bytes from 173.194.75.103: icmp_seq=0 ttl=46 time=25.218 ms
64 bytes from 173.194.75.103: icmp_seq=1 ttl=46 time=23.944 ms
64 bytes from 173.194.75.103: icmp_seq=2 ttl=46 time=24.213 ms
64 bytes from 173.194.75.103: icmp_seq=3 ttl=46 time=78.480 ms
64 bytes from 173.194.75.103: icmp_seq=4 ttl=46 time=24.502 ms
^C
--- www.google.com ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 23.944/35.271/78.480/21.608 ms
bschott@ironman:django-nimbis$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyname('www.google.com')
'173.194.75.147'
>>> socket.getaddrinfo('www.google.com', 80)
[(2, 1, 6, '', ('74.125.131.106', 80)), (2, 1, 6, '', ('74.125.131.147', 80)), (2, 2, 17, '', ('74.125.131.106', 80)), (2, 2, 17, '', ('74.125.131.99', 80)), (2, 1, 6, '', ('74.125.131.99', 80)), (2, 2, 17, '', ('74.125.131.104', 80)), (2, 1, 6, '', ('74.125.131.104', 80)), (2, 2, 17, '', ('74.125.131.105', 80)), (2, 1, 6, '', ('74.125.131.105', 80)), (2, 2, 17, '', ('74.125.131.103', 80)), (2, 1, 6, '', ('74.125.131.103', 80)), (2, 2, 17, '', ('74.125.131.147', 80)), (30, 1, 6, '', ('2607:f8b0:400c:c03::93', 80, 0, 0)), (30, 2, 17, '', ('2607:f8b0:400c:c03::93', 80, 0, 0))]