最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】公司Wi-Fi更换运营商导致IP变化导致远程Mongo连不上

MongoDB crifan 2881浏览 0评论

公司内,几个同事,之前是用

江苏省苏州市 移动

的Wi-Fi网络上网的。

然后开发期间,连接远程服务器中的mongo

为了安全,做了端口限制的

所以当时是把公司几个人的IP都加到阿里云ECS的安全组中:

然后也就正常连接mongo,继续开发了。

然后此刻突然发现:

同事的,我的,都连不上远程mongo了:

➜  ~ mongo gridfs –host xx.xx.xx.xx –port 12345 -u gridfs -p pwd –authenticationDatabase gridfs

MongoDB shell version v3.6.3

connecting to: mongodb://x.x.x.x:12345/gridfs

2018-05-10T10:25:22.189+0800 W NETWORK  [thread1] Failed to connect to x.x.x.x:12345 after 5000ms milliseconds, giving up.

2018-05-10T10:25:22.190+0800 E QUERY    [thread1] Error: couldn’t connect to server xx.xx.xx.xx:12345, connection attempt failed :

connect@src/mongo/shell/mongo.js:251:13

@(connect):1:6

exception: connect failed

然后去服务器上看看:

[root@naturling-general-01 ~]# systemctl status mongod

● mongod.service – SYSV: Mongo is a scalable, document-oriented database.

   Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)

   Active: active (running) since Tue 2018-04-24 17:28:25 CST; 2 weeks 1 days ago

     Docs: man:systemd-sysv-generator(8)

   CGroup: /system.slice/mongod.service

           └─1165 /usr/bin/mongod -f /etc/mongod.conf

Apr 24 17:28:24 naturling-general-01 systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database….

Apr 24 17:28:24 naturling-general-01 runuser[1142]: pam_unix(runuser:session): session opened for user mongod by (uid=0)

Apr 24 17:28:25 naturling-general-01 runuser[1142]: pam_unix(runuser:session): session closed for user mongod

Apr 24 17:28:25 naturling-general-01 mongod[1122]: Starting mongod: [  OK  ]

Apr 24 17:28:25 naturling-general-01 systemd[1]: Started SYSV: Mongo is a scalable, document-oriented database..

服务器中mongod是正常在运行的啊。

试试重启mongod:

[root@naturling-general-01 ~]# systemctl restart mongod

问题依旧。

试试服务器中本地mongo连接mongod:

[root@naturling-general-01 ~]# mongo gridfs –port 12345 -u gridfs -p PN@wd –authenticationDatabase gridfs

MongoDB shell version: 3.2.19

connecting to: 127.0.0.1:12345/gridfs

是没问题的。

那就怪了。

然后想到去看看服务器的安全组是否有问题,也是没问题的。

然后想到,不会是网络IP地址变化了吧?

去看看,竟然,果然,是:

之前的IP是:

【已解决】用工具或网站查询自己本地的网络的IP地址

中的:

而现在的是:

IP.cn – IP 地址查询 | 地理位置 | 手机归属地

https://ip.cn

您现在的 IP:222.92.130.218

所在地理位置:江苏省苏州市 电信

GeoIP: Suzhou, Jiangsu, China

显示查询自己的IP地址

http://ip111.cn

检测点
检测结果
解释
国内网站
222.92.130.218 China / Nanjing
如果没有全局代理或者VPN,左侧显示的IP就是您本机的IP。如果有,则显示的就是全局代理或者VPN的IP地址。
国外网站 
222.92.130.218
左侧IP就是您用来访问国外普通网站(没有被封的网站)的IP地址。
谷歌网站
104.245.14.85
左侧如果没有显示一个IP地址,则说明您现在还不能科学上网,不能访问谷歌,Facebook,Twitter等国外网站。显示IP则表示可以科学上网,这个IP地址就是您用来科学上网的IP地址,通常是您的SS服务器的IP地址,或者VPN服务器,代理服务器的IP地址。

很明显说明是:

  • 此处公司WIFI之前是:苏州移动

    • 每个同事的网络出口的IP都是一个IP地址段,但不是同一个IP,比如:

      • 112.4.64.138

      • 112.4.64.140

      • 112.4.64.141

  • 现在公司WI-FI是:苏州电信

    • 每个同事的网络出口IP都是同一IP地址

      • 222.92.130.218

找到原因后,就知道如何解决了:

去安全组中加上对应的IP地址:

然后本地就可以连接远程mongo了:

➜  ~ mongo gridfs –host xx.xx.xx.xx –port 12345 -u gridfs -p ppwwdd –authenticationDatabase gridfs

MongoDB shell version v3.6.3

connecting to: mongodb://xx.xx.xx.xx:12345/gridfs

MongoDB server version: 3.2.19

WARNING: shell and server versions do not match

>

转载请注明:在路上 » 【已解决】公司Wi-Fi更换运营商导致IP变化导致远程Mongo连不上

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.181 seconds, using 22.06MB memory