Running Mongo 3.0.3 on Centos6.5. Running app with pymongo (python3.4) from a different server.
Can only get connection from remote server to work by commenting out bind_ip completely, which I'm a bit worried about. How can bind_ip be set to accept connections from specific IP of remote server and from localhost?
I tried:
bind_ip = 127.0.0.1 # only local works
bind_ip = 127.0.0.1, <remote server IP> # all traffic stops
The bind_ip configuration option in mongodb is for attaching mongos or mongod process to listen to specific network interface. As you may know a server may have multiple network interfaces, you may choose on which interface you want mongos/mongod to listen for connections.
If I put it simply, bind_ip configuration allows attaching mongos/mongod process to one or multiple ips that are available on a server so that it will listen for connection requests coming on the specific ip/ips. bind_ip sometimes confuses beginers. They may feel that bind_ip is for allowing an ip FROM where connections to the mongodb are allowed. But this is not true.
For example, suppose you have a server that has 2 network interface i.e x.x.x.x and y.y.y.y
Now if you run mongod process on this server and use x.x.x.x in bind_ip configuration then you can connect to this mongod from anywhere if you use x.x.x.x:27017 in your connection string. Though the other ip is also on the same server but you will not be able to connect to this mongod using y.y.y.y:27017 in your connection string. Similarly, if you bind your mongos/mongod to 127.0.0.1 then you will only be able to connect to it from the server itself.
Hope this helps.
Related
I've successfully installed MongoDB on Windows (on a local machine) as a service, but now I want to move MongoDb to a separate server. So I extracted the tarball to a virtual server on network (running linux).
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 to the default 28017 port. The mongo console is also working and allowed me to create a new database (testdb) and add users to it.
However, I could not access the server from remote. When I type testmongoserver:28017 it doesn't open the HTTP console as localhost:28017 on my local machine does. I also can't connect using official drivers and providing a connectionstring.
What are the neccesarry steps to install MongoDB on Linux, so that I could access it from a remote machine with a connectionstring and use its HTTP console via testmongoserver:28017
Thanks!
1. Bind IP option
Bind IP is a MongoDB option that restricts connections to specifics IPs.
Have a 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 your desired IP by concatenating a list of comma separated values to bind MongoDB to multiple IP addresses.
Remove or comment (with # character) the bind_ip line. But be aware that all remote connection will be able to connect your MongoDB server!
More about bind_ip configuration option: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp
Bind IP can also be set as a command argument: http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--bind_ip
2. Firewall
Check that you are not running behind a firewall
Make sure in your /etc/mongodb.conf file you have the following line,
bind_ip = 0.0.0.0
http://jitu-blog.blogspot.com.br/2013/06/allow-mongo-to-connect-from-remote-ip.html
Run netstat -a on mongo server and check a port.
Check DNS settings and check that linux server allows external connections.
Check that mongodb can accept external/remote connection.
Default port for mongo is 27017.
28017 - port for webstats.
See http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-Ports
Just had this issue and this fixed it:
Edit /etc/mongod.conf with sudo nano /etc/mongod.conf ensure that the net section looks like below (localhost binding by default doesn't allow for remote access):
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
Make sure to restart mongod when you are done with above with below (assuming systemd ubuntu 16.04+ etc.):
sudo service mongod restart
Obviously from a security perspective if you are going to be opening up mongo to your network/the world be aware of the implications of this (if any)
Another problem may be that the mongodb port is not enabled. Check, from another host, the ports enabled on your server. For that you can use the command:
sudo nmap -P0 your_server_ip
You can get an answer like this:
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 use a virtual server in the cloud, as AWS, you need to add a new rule to add mongodb port (27017 by default).
Important: Note that with this configuration anyone can have access to your database
I fixed by below reference :
https://medium.com/founding-ithaka/setting-up-and-connecting-to-a-remote-mongodb-database-5df754a4da89
Actually, first i changed my bindIp from 127.0.0.1 to 0.0.0.0 in mongod.conf,
and enable security:
security:
authorization: "enabled"
then i restarted mongod using sudo service mongod restart.(because of new changes in mongod.conf), after that set firewall to open mongod running port (by iptables) and create a new user in admin db with new access (based on this link : https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac), finally test open ports in my server from outside with (https://www.yougetsignal.com/tools/open-ports/) and connected successfully to remote mongod using mongocompass.exe.
I've successfully installed MongoDB on Windows (on a local machine) as a service, but now I want to move MongoDb to a separate server. So I extracted the tarball to a virtual server on network (running linux).
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 to the default 28017 port. The mongo console is also working and allowed me to create a new database (testdb) and add users to it.
However, I could not access the server from remote. When I type testmongoserver:28017 it doesn't open the HTTP console as localhost:28017 on my local machine does. I also can't connect using official drivers and providing a connectionstring.
What are the neccesarry steps to install MongoDB on Linux, so that I could access it from a remote machine with a connectionstring and use its HTTP console via testmongoserver:28017
Thanks!
1. Bind IP option
Bind IP is a MongoDB option that restricts connections to specifics IPs.
Have a 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 your desired IP by concatenating a list of comma separated values to bind MongoDB to multiple IP addresses.
Remove or comment (with # character) the bind_ip line. But be aware that all remote connection will be able to connect your MongoDB server!
More about bind_ip configuration option: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp
Bind IP can also be set as a command argument: http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--bind_ip
2. Firewall
Check that you are not running behind a firewall
Make sure in your /etc/mongodb.conf file you have the following line,
bind_ip = 0.0.0.0
http://jitu-blog.blogspot.com.br/2013/06/allow-mongo-to-connect-from-remote-ip.html
Run netstat -a on mongo server and check a port.
Check DNS settings and check that linux server allows external connections.
Check that mongodb can accept external/remote connection.
Default port for mongo is 27017.
28017 - port for webstats.
See http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-Ports
Just had this issue and this fixed it:
Edit /etc/mongod.conf with sudo nano /etc/mongod.conf ensure that the net section looks like below (localhost binding by default doesn't allow for remote access):
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
Make sure to restart mongod when you are done with above with below (assuming systemd ubuntu 16.04+ etc.):
sudo service mongod restart
Obviously from a security perspective if you are going to be opening up mongo to your network/the world be aware of the implications of this (if any)
Another problem may be that the mongodb port is not enabled. Check, from another host, the ports enabled on your server. For that you can use the command:
sudo nmap -P0 your_server_ip
You can get an answer like this:
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 use a virtual server in the cloud, as AWS, you need to add a new rule to add mongodb port (27017 by default).
Important: Note that with this configuration anyone can have access to your database
I fixed by below reference :
https://medium.com/founding-ithaka/setting-up-and-connecting-to-a-remote-mongodb-database-5df754a4da89
Actually, first i changed my bindIp from 127.0.0.1 to 0.0.0.0 in mongod.conf,
and enable security:
security:
authorization: "enabled"
then i restarted mongod using sudo service mongod restart.(because of new changes in mongod.conf), after that set firewall to open mongod running port (by iptables) and create a new user in admin db with new access (based on this link : https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac), finally test open ports in my server from outside with (https://www.yougetsignal.com/tools/open-ports/) and connected successfully to remote mongod using mongocompass.exe.
I am new to MongoDB, so excuse me for a basic question but.
I am running MongoDB (3.6, Professional) on a Windows PC. I have managed to add it as a Windows Service to start automatically on Startup.
However, it binds to 127.0.0.1 or localhost.
The IP on that PC is 192.168.1.10 and I would like to access the server from different LAN PCs.
When I run Mongo, I get:
WARNING: This server is bound to localhost. Remote systems will be
unable to connect to this server. Start the server with --bind_ip
to specify which IP
addresses it should serve responses from, or with --bind_ip_all to
bind to all interfaces. If this behavior is desired, start the
server with --bind_ip 127.0.0.1 to disable this warning.
So I went to Services.msc, and added --bind_ip_all as a parameter, and restarted the service. But get the same warning. How can I get my MongoDB service to bind to all, or better yet, bind_ip = 127.0.0.1,192.168.1.10?
I may have resolved this, but not sure if it's the right way.
I removed the service.
I recreated the service, but added a conf parameter and provided a
path to my config file.
C:\Program Files\MongoDB\Server\3.6\bin>mongod
--dbpath=C:\Storage\database\mongodb\data --logpath=C:\Storage\database\mongodb\logs --config "C:\Program Files\MongoDB\Server\3.6\bin\mongod.conf" --install
I created a config file:
Listen to local and LAN interfaces.
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,192.168.1.10 # Listen to local interface only, comment to listen on all interfaces.
It seems I can now bind to both localhost and my IP address..
I have an Ubuntu server with mongodb installed. Is it possible to configure mongodb in such a way that I can connect to it using only localhost and its LAN IP address.
The default mongo configuration works fine for connecting using localhost:
bind_ip = 127.0.0.1
If I change to the LAN IP, then I am only able to connect using that IP, and not using localhost:
bind_ip = 10.10.10.10
If I try to add both, then I get an address in use error and doesn't start:
bind_ip = 127.0.0.1, 10.10.10.10
If I remove the bind_ip setting, then both work, but I am also able to connect with the servers external IP (which I do not want).
#bind_ip = 127.0.0.1, 10.10.10.10
So, how can I tell mongo to listen on the local interface, but allow connections from both localhost and its LAN IP?
With the help of #wdberkeley's comment, I realized that the problem was the space after the , in the list of IP addresses the bind to. However, it seems that this issue only affects the old config file format (not YAML).
# This Works:
bind_ip = 127.0.0.1,10.10.10.10
# This doesn't work:
bind_ip = 127.0.0.1, 10.10.10.10
Bind to address 0.0.0.0 this will allow it to answer regardless of the IP address being used and even on machines that have multiple network cards with different IP addresses
I am trying to use MongoDB for remote connection. First I tried localhost and internal ip address to build the connection. Both of them succeeded. Then I tried external ip address to connect on my own computer of MAC as an experiment first. I have created an admin user for the database in MongoDB. The bind_ip option is also commented in mongodb.conf. The firewall should also have been turned down. But the connection cannot been built still. Does anyone know the reason?
Thank you very much!
To allow connecting remote clients (which is your case) to MongoDB Server.
Make sure to do set bind_ip to either of values, in your mongodb.conf file -
Following is with any IP
bind_ip = 0.0.0.0
Following for bind to specific IP
bind_ip = 10.52.36.99 (or any specific IP)