1
votes

I changed bindIp setting to

bindIp: 127.0.0.1, 0.0.0.0

in mongod.conf on my ubuntu server hosted on Linode and restarted mongod and status looks ok.

I opened mongodb port on ufw

sudo ufw status Status: active

To Action From -- ------ ---- 22/tcp ALLOW Anywhere 10000
ALLOW Anywhere Nginx Full
ALLOW Anywhere 3333
ALLOW Anywhere 27017
ALLOW Anywhere 22/tcp (v6)
ALLOW Anywhere (v6) 10000 (v6)
ALLOW Anywhere (v6) Nginx Full (v6)
ALLOW Anywhere (v6) 3333 (v6)
ALLOW Anywhere (v6) 27017 (v6)
ALLOW Anywhere (v6)

Connecting to it from my mac throws error:

mongo mongodb://admin:secret@ubuntuipaddress/fielddb?authSource=admin MongoDB shell version v3.6.2 connecting to: mongodb://ubuntuipaddress/fielddb?authSource=admin 2018-04-08T13:47:32.212 W NETWORK [thread1] Failed to connect to ubuntuipaddress:27017, in(checking socket for error after poll), reason: Connection refused 2018-04-08T13:47:32.214 E QUERY
[thread1] Error: couldn't connect to server ubuntuipaddress:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6 exception: connect failed

How to fix this issue?

3
Can you telnet ubuntuipaddress 27017 from your Mac? - Praveen Premaratne
telnet to 27017 I get connection refused error but telnet to 3333 works fine - ace
Not too sure what's running on 3333. But, try running sudo ufw allow 27017/tcp? - Praveen Premaratne
I tried sudo ufw allow 27017/tcp and confirm that this change was made but it did not make any dfference - ace
Can you change the public port that MongoDB listens on to something else? - Praveen Premaratne

3 Answers

2
votes

The basic steps for enabling remote access for Mongodb running on Ubuntu are:

  1. Setup a minimum of one user in Mongodb (admin with root rights)
  2. Edit the config file (i.e. sudo nano etc/mongodb.conf)
  3. Make sure that
bind_ip = 0.0.0.0 
port = 27017 
auth = true 

are set (and uncommented)

  1. Add a firewall rule in UFW to allow 27017 from your remote IP address (or anywhere)

You should be good to go.

1
votes

Disable your firewall and try to see if you can connect, if you can then it's your fw rules. Try this first to see if this helps.

1
votes

The problem was wrong setting of bindIP in mmongod.conf. Changing to:

bindIp: 127.0.0.1,ip_address_of_host_running_mondgod

fixed the problem. Replace ip_address_of_host_running_mondgod with ip address of host running mongod like 137.142.177.4