I have mongo installed on Centos instance in AWS and I am connecting to the mongoDB server from my system. To connect from remote system we need to change bind_ip value to in /etc/mongod.conf file and have done the same thing. Still I am not able to connect to the mongoDB from my system. When I checked weather the changed bind_ip is reflecting or not using netstat -a command the result is

tcp  0  0   localhost:27017*    LISTEN

but, to connect from remote system it should be

tcp  0  0*    LISTEN

So the change in bind_ip value is not reflecting. Can anyone help on this?

  • Welcome to the site.What is the MongoDB version(x,y,z)? – Md Haidar Ali Khan Nov 15 '18 at 15:39

tcp 0 0 localhost:27017* LISTEN

As per @Jay Gordon blog documented here This output means that users are only permitted to access our MongoDB instance on port 27017 via IP

Starting in MongoDB 3.6, mongos bind to localhost by default. See Default Bind to Localhost.

The hostnames and/or IP addresses and/or full Unix domain socket paths on which mongos should listen for client connections. You may attach mongos to any interface. To bind to multiple addresses, enter a list of comma-separated values.



Note: When possible, use a logical DNS hostname instead of an ip address, particularly when configuring replica set members or sharded cluster members. The use of logical DNS hostnames avoids configuration changes due to ip address changes.

To bind to all IPv4 addresses, enter

To bind to all IPv4 and IPv6 addresses, enter ::, or alternatively, use the net.bindIpAll setting.

Enable Access Control and Enforce Authentication

Enable access control and specify the authentication mechanism. You can use the default MongoDB authentication mechanism or an existing external framework. Authentication requires that all clients and servers provide valid credentials before they can connect to the system. In clustered deployments, enable authentication for each MongoDB server.

See Authentication and Enable Auth.

WARNING: Before you bind to other ip addresses, consider enabling access control and other security measures listed in Security Checklist to prevent unauthorized access.

If you would like to make this available to other systems on your network, you'll want to bind the local IP associated with the private network. To determine network interface configuration easily, we can just run an ifconfig from the command line:

For Example

To determine network interface configuration easily, we can just run an ifconfig from the command line:

ubuntu@ip-172-16-0-211:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 0e:5e:76:83:49:3e
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::c5e:76ff:fe83:493e/64 Scope:Link
          RX packets:65521 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7358 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:94354063 (94.3 MB)  TX bytes:611646 (611.6 KB)

We have the IP we want to make part of the list of acceptable network addresses we can listen from. I will open the /etc/mongodb.conf file and edit it to reflect the additional network IP:

The file's changes will be:

# network interfaces
  port: 27017

After modifying bindIP under "net" from just to include private IP address, we should be able to restart and see it listening from netstat on both now:

ubuntu@ip-172-16-0-211:~$ sudo service mongod stop
ubuntu@ip-172-16-0-211:~$ sudo service mongod start
ubuntu@ip-172-16-0-211:~$ sudo netstat -plnt | egrep mongod
tcp        0      0*               LISTEN      2892/mongod
tcp        0      0*               LISTEN      2892/mongod

For further your ref here and here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.