0

I have mongodb running and I want to access it from an external machine

Output from ufw status

Status: active

To                         Action      From
--                         ------      ----
80                         ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
27017                      ALLOW       Anywhere
80 (v6)                    ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)
27017 (v6)                 ALLOW       Anywhere (v6)

output from telnet 27017

Connecting To <ip>...Could not open connection to the host, on port 27017: Connect failed

output from netstat -tulpn

Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      
tcp        0      0 0.0.0.0:433             0.0.0.0:*               LISTEN      
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      

sudo systemctl status mongod

 * mongod.service - High-performance, schema-free document-oriented database
  Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
  Active: active (running) since Tue 2019-01-15 07:20:51 CET; 51min ago
  Docs: https://docs.mongodb.org/manual

I have tried reinstalling mongo, restarting ufw etc...What am I doing wrong?

4

I guess ufw is not problem, but netstat shows 127.0.0.1:27017, which is incorrect if you want to access port 27017 from externally. You have to change your MongoDB configuration from bindIp: 127.0.0.1 to bindIp: 0.0.0.0 and restart mongod.service.

2
  • @jinyus please don't comment to say "thank you" but vote up and accept the answer to indicate that is correct and/or helped you resolve your problem. – HBruijn Jan 15 '19 at 13:29
  • in a python server you set the actual server host ip address instead of 0.0.0.0 – jmarina Feb 21 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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