通过mongo shell连接到mongodb和ipv6

时间:2016-10-25 21:03:25

标签: mongodb ipv6 mongo-shell

我能够在mongodb上启用ipv6。

/etc/mongod.conf file has net.ipv6 set to true.

我可以看到mongodb在监听ipv6:

# netstat -anp | grep 27017
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      17967/mongod        
tcp6       0      0 :::27017                :::*                    LISTEN      17967/mongod        
unix  2      [ ACC ]     STREAM     LISTENING     19750206 17967/mongod         /tmp/mongodb-27017.sock
#

ping6到IPv6地址没问题。

[root@tesla05 log]# ping6 -I eno33554952 tesla05-2-ipv6.ulticom.com
PING tesla05-2-ipv6.ulticom.com(tesla05) from fe80::250:56ff:feb4:7c43 eno33554952: 56 data bytes
64 bytes from tesla05: icmp_seq=1 ttl=64 time=0.101 ms
64 bytes from tesla05: icmp_seq=2 ttl=64 time=0.093 ms
64 bytes from tesla05: icmp_seq=3 ttl=64 time=0.091 ms

但是,mongo shell似乎不了解ipv6地址。

[root@tesla05 log]# mongo --ipv6 [fe80::250:56ff:feb4:7c43]:27017/admin
MongoDB shell version: 3.2.4
connecting to: [fe80::250:56ff:feb4:7c43]:27017/admin
2016-10-25T12:04:50.401-0400 W NETWORK  [thread1] Failed to connect to fe80::250:56ff:feb4:7c43:27017, reason: errno:22 Invalid argument
2016-10-25T12:04:50.402-0400 E QUERY    [thread1] Error: couldn't connect to server [fe80::250:56ff:feb4:7c43]:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6

exception: connect failed

[root@tesla05 log]# mongo --ipv6 tesla05-2-ipv6.ulticom.com:27017/admin
MongoDB shell version: 3.2.4
connecting to: tesla05-2-ipv6.ulticom.com:27017/admin
2016-10-25T12:15:17.861-0400 W NETWORK  [thread1] Failed to connect to fe80::250:56ff:feb4:7c43:27017, reason: errno:22 Invalid argument
2016-10-25T12:15:17.861-0400 E QUERY    [thread1] Error: couldn't connect to server tesla05-2-ipv6.ulticom.com:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6

exception: connect failed

1 个答案:

答案 0 :(得分:3)

您正在尝试使用链接本地IPv6地址。如果没有范围,这些无效,但您没有提供。因此,您收到错误Invalid argument。因此,在DNS中放置链接本地地址是没有意义的,因为该地址仅在特定LAN上有效,并且该LAN上的每个主机的范围可能不同。

要使用该地址,请将范围附加到该地址,例如fe80::250:56ff:feb4:7c43%eno33554952