How to set up mongoDB bindIp? - mongodb

Something wrong happens when I'm trying to setup mongod.conf for connection from remote server.
When I paste my server ip address Mongo doesn't allow connection from it.
# network interfaces
net:
port: 27017
bindIp: 111.111.11.111 #my server ip
When I allow connection from any server, mongo allows to connect from my server.
net:
port: 27017
bindIp: 0.0.0.0
I want to have an access to Mongo from localhost and from my server. I'm trying to paste these ip's both but Mongo allow connection from localhost only.
net:
port: 27017
bindIp: 127.0.0.1 111.111.11.111
What's wrong and how to use bindIp ?

According to documentation the value is a string, i.e. a single value.
Try following:
Use only 111.111.11.111, localhost may work by default anyway.
Try these ones:
net:
port: 27017
bindIp:
- 127.0.0.1
- 111.111.11.111
net:
port: 27017
bindIp: 127.0.0.1,111.111.11.111
net:
port: 27017
bindIp: [127.0.0.1,111.111.11.111]
Otherwise use a firewall, either an external one or the internal firewall of your operating system.

I thought there has to be the IP address of the remote server. It's not right. There can be ip addresses of the network interfaces of the current machine.
Looking for here:
ifconfig -a | grep "inet"

Related

unable to connect mongod from remote and local on IP address

My mongod servers runs on IP 67.219.110.71 and default port 27017
Below is the command to start mongod
mongod --dbpath /data/db --fork --logpath /dev/null
After login to the linux server 67.219.110.71 I'm able to telnet successfully like below:
telnet localhost 27017 ----> SUCCESS
However, when I telnet using the IP address it does not connect from the same host 67.219.110.71 or from a remote hots both fail
telnet 67.219.110.71 27017 ----> FAILS
Note:
have restarted the mongod service several times and after any configuration change.
port 27010 was opened on the firewall using firewall-cmd command.
I'm able to connect on ssh port telnet 67.219.110.71 22 ----> SUCCESS
Below is my mongod configuration file /etc/mongod.conf:
# mongod.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,67.219.110.71,0.0.0.0,:: # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
# bindIpAll: true
# bindIp: 0.0.0.0
security:
authorization: "enabled"
Can you please suggest?

Mongoose connection error: MongoError: failed to connect to server

I was running mongo 3.4 on centOS. It was using authorization. I needed to upgrade it to mongo 3.6. I upgraded it and now I'm not able to connect it through any means remotely. Neither with the shell nor with the node server itself.
Here is the mongoose connection.
const uri = 'mongodb://admin:12345#host:27017/db?authSource=admin';
mongoose.connect(uri);
Here is mongod.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
Probably the upgrade was not successful, and the restart of the mongod service failed.
View the logs in /var/log/mongodb/mongod.log and check for any inconsistency in the mongod.conf.
Check if the service is up and if it is listening on port 27017.
service mongod status
netstat -tl | grep 27017 # or using the ss command
ss -tl | grep 27017
From the official documentation:
Starting in MongoDB 3.6, mongod and mongos instances bind to localhost by default. Remote clients cannot connect to an instance bound only to localhost. To override and bind to other ip addresses, use the net.bindIp configuration file setting or the --bind_ip command-line option to specify a list of ip addresses.
Try the following setting to enable the service to listen on all the interfaces
net:
port: 27017
bindIp: 0.0.0.0

Why Mongodb config changes not getting applied?

I am running Mongodb on AWS windows instance, I changed my config setting as following:
net:
port: 30000
bindIp: 0.0.0.0
As far as my knowledge, Server should get started on port 30000, it can listen request from other ip as well
However, on restarting mongod, it is still running on localhost and listening to port 27017
I have the same problem with you. What I did is a workaround it. I start the service with specifying the port and ip.
mongod --auth --port 30000 --dbpath /data/db --bind_ip_all

How to configure new port for mongodb

I am currently using port 27017 for mongodb and everything is working proper. We want to configure new port for security purpose.
Can you help me how we can configure this?
This way,
While startiing mongo pass port argument
mongod --port your desired port
mongod --port 19000
Start Mongo with port:
mongo --port your desired port
mongo --port 19000
2.change the port in the mongodb.config file and pass the config file as input.
port = Ur desired port
Change the /etc/mongod.conf file for persistence
change net: section as
net:
bindIp: 127.0.0.1
port: <The port number you want to listen>
Command line option --port <port> can also be used but will not remain persistent and you need to specify the same every time you start Mongod

cannot connect to MongoDB, Ubuntu 64 VM ( Vagrant, PuPHPet )

Downloaded and tried a couple of different versions from puphpet.com just to be sure. Here is the mongo part of code from puphpet config.yaml:
mongodb:
install: '1'
settings:
auth: 1
port: '27017'
databases:
kxuqYQ6plcMS:
name: awesome
user: admin
password: '1234'
IMPORTANT ! I can run mongo in git shell, and mongod service is running, but cannot access it from outside.
mongodb conf :
bind_ip = 0.0.0.0
port = 27017
auth = 1
I've tried commenting the bind_ip, without success. During Robomongo connection i also tried with ssh, specifying
SSH_adress = 127.0.0.1:22
username = vagrant
password = vagrant
and also authentication, but that does not matter since it cannot connect
The same was happening to me.
I added the following lines at the end of the Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 27017, host: 27017
end
And changed in /etc/mongodb.conf bind_ip to 0.0.0.0
bind_ip = 0.0.0.0
Restarted mongodb and after that I could connect to it through the host and Robomongo
I think the issue is probably that you did not add the Mongo port to the firewall section. The port is accessible from inside the VM, but anything outside of it needs to be cleared by iptables.
Just add to the firewall section within your config.yaml