MongoDB bind_ip error: bind() failed errno:99 Cann

2020-05-31 16:58发布

问题:

I want to configure mongodb to allow remote connections from an external ip address like 66.31.123.123.

Setting 0.0.0.0 to bind_ip works, but I want to be more restrictive and only allow certain ip addresses to connect. I appended 66.31.123.123 to the bind_ip list but mongodb throws an error below:

mongodb.conf

bind_ip = 127.0.0.1,66.31.123.123
port = 27017

auth = true

mongodb logs

Mon Dec  9 03:25:59 [initandlisten] ERROR: listen(): bind() failed errno:99 Cannot assign requested address for socket: 66.31.123.123:27017

Question: Why does adding an external ip not work? If auth=true is used, does that make it safe enough to use 0.0.0.0 as the bind_ip? The mongodb will be locally accessed from a Meteor.js app.

回答1:

As guido said, the bind_ip is for the mongo server's own IP address.

Auth is a good idea but only relying on auth opens you up to a brute force attack.

You could bind_ip = 0.0.0.0 and use a firewall to block all incoming connections to port 27017, unless coming from 66.31.123.123.

Another concern is proximity of your meteor server to your mongo server — is it on private networking or across public network. If across public, you should either recompile mongodb to support SSL, or you should tunnel your mongodb connection through SSH.

If you do decide to tunnel, bind_ip to 127.0.0.1 and leave out incoming 27017.