我在办公室环境中遇到了最奇怪的行为,我无法使用开关设备。启用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))]
答案 0 :(得分:0)
如果启用了IPv6,是否会获得正确的IPv4地址和默认路由?听起来好像你有一些奇怪的设置运行NAT64。如果使用AI_ADDRCONFIG调用,getaddrinfo将不会返回IPv4地址。
host
实用程序不使用系统查找例程,而是使用自己的网络代码,因此dscacheutil -flushcache
不会影响它。