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?
Best Answer
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
tobindIp: 0.0.0.0
and restart mongod.service.