Connection refused for remote access of mongodb server

Hey @Jingyang_Wang,

Welcome to the MongoDB Community!

By default, MongoDB binds to a localhost IP address. In the post, you mentioned <my ip address>. Could you clarify what this address is? Is this address 127.0.0.1, or some other address? Is it accessible from outside the node?

Based on the details you provided, it seems the issue is that the MongoDB server is only listening for connections on the local interface and not on your public IP address.

May I ask what steps you followed to install MongoDB?

Moreover, a few things to check:

  • In the MongoDB config file (usually /etc/mongod.conf), make sure the bindIp have the IP address of your other system or set to 0.0.0.0 to bind to all available IP addresses.
  • Restart the MongoDB service after making any config changes.
  • Verify the MongoDB process is actually listening on the public IP by running netstat -an | grep 27017 on the server. You should see it listening on 0.0.0.0:27017 or the public IP.

If the issue still persists, some other things to check would be the network/firewall configuration on the server, making sure the public IP is certainly assigned to the server, or checking for any other processes that may be blocking port 27017.

Please note 0.0.0.0 is not recommended for your production environment as it allows access from anywhere.

Hope the above helps!

Regards,
Kushagra

2 Likes