Getting MongoDB on Linux to listen for remote connections

I have successfully installed MongoDB on Windows (on the local computer) as a service, but now I want to move MongoDb to a separate server. So I pulled tarball to a virtual server on the network (linux is running).

When I connected to the server ("testmongoserver") using PuTTY from my local machine, I started the mongod server and it told me that it was listening on port 28017 by default. The mongo console also works and allows me to create a new database (testdb) and add users to it.

However, I could not access the server from a remote server. When I type "testmongoserver: 28017", it does not open the HTTP console as "localhost: 28017" on my local machine. I also cannot connect using official drivers and provide a connection string.

What are the neccesarry steps for installing MongoDB on Linux so that I can access it from a remote machine using a connecting line and use its HTTP console through testmongoserver: 28017

Thank!

+46
linux mongodb networking
Aug 23 '11 at 10:37
source share
5 answers
  • Run netstat -a on the mongo server and check the port.
  • Check your DNS settings and make sure your linux server supports external connections.
  • Make sure mongodb can accept external / remote connections.

The default port for mongo is 27017. 28017 is the port for websites.

See http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-Ports

+18
Aug 23 '11 at 12:50
source share

1. IP Binding Option

Bind IP is a MongoDB option that restricts connections to specific IP addresses.

Look at your mongod configuration file, most of the time bind_ip is set to 127.0.0.1 for obvious security reasons. You can:

  • Add the desired IP address by combining a comma-separated list of values ​​to bind MongoDB to multiple IP addresses.
  • Delete or comment out (with #) bind_ip string. But keep in mind that an entire remote connection will be able to connect your MongoDB server!

More on configuring bind_ip: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp

Bind IP can also be specified as an argument to the command: http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--bind_ip

2. Firewall

Make sure you are not working behind a firewall

+73
Sep 12 '13 at 16:41
source share

Make sure the following line is in the /etc/mongodb.conf file,

bind_ip = 0.0.0.0 

http://jitu-blog.blogspot.com.br/2013/06/allow-mongo-to-connect-from-remote-ip.html

+27
Jul 17 '14 at 3:21
source share

Another problem may be that the mongodb port is not enabled. Check the ports included on your server from another host. To do this, you can use the command:

 sudo nmap -P0 your_server_ip 

You can get the answer as follows:

 Host is up (0.052s latency). Not shown: 997 filtered ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp closed https 

If you are using a virtual server in the cloud like AWS, you need to add a new rule to add the mongodb port (default is 27017).

It is important . Please note: in this configuration, any user can have access to your database

enter image description here

+1
Mar 23 '16 at 16:18
source share

Just this problem and it is fixed:

Change /etc/mongod.conf to sudo nano /etc/mongod.conf make sure the network section looks lower (binding to the local host does not allow remote access by default):

 # network interfaces net: port: 27017 bindIp: 0.0.0.0 

Be sure to restart mongod when you are done with the above (assuming systemd ubuntu 16.04+, etc.):

sudo service mongod restart

0
Dec 18 '17 at 2:21 on
source share



All Articles