Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Im trying to connect to a mongodb server over a network but I cant get the connection to work.

I can connect like so on the local computer on which the server is running:

mongo localhost:27027

But connecting from a remote computer fails (where = the database hosts ip):

mongo <public_ip>:27027

Tue Mar 18 10:40:30 Error: couldn't connect to server <public_ip>:27017 shell/mongo.js:86

exception: connect failed

Notably this is response is different when the port is disallowed and rather than the exception: connect failed error I get a timeout.

I have a firewall (ufw) but port 27027 is set to accept any connections. I also tried stopping the firewall altogether but had no joy.

What should I try to debug this problem, is there anything obvious I'm doing wrong?

Here's some extra info from the host computer that may be useful:

jon@lfmaster:~$ sudo ufw status
[sudo] password for jon: 
Status: active

To                         Action      From
--                         ------      ----
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
22                         ALLOW       Anywhere
111                        ALLOW       Anywhere
2049                       ALLOW       Anywhere
27017                      ALLOW       Anywhere
28017                      ALLOW       Anywhere
80                         ALLOW       Anywhere (v6)
443                        ALLOW       Anywhere (v6)
22                         ALLOW       Anywhere (v6)
111                        ALLOW       Anywhere (v6)
2049                       ALLOW       Anywhere (v6)
27017                      ALLOW       Anywhere (v6)
28017                      ALLOW       Anywhere (v6)

-

jon@lfmaster:~$ sudo lsof -i
COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
...
mongod    1184 mongodb    6u  IPv4   9911      0t0  TCP localhost:27017 (LISTEN)
mongod    1184 mongodb    8u  IPv4   9913      0t0  TCP localhost:28017 (LISTEN)
share|improve this question

1 Answer 1

up vote 3 down vote accepted

If you need to use a nonstandard port you need to use the --port switch from the command line mongo <public ip> --port 27027

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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