As a general rule, most servers only allow connections to MongoDB locally, that is, from the Cloud server itself and not from an external server or computer.
In “setups” where it is necessary to configure MongoDB on a separate server, to avoid overloading the web front end, for example, some configuration is required to connect remotely to the databases.
Below we explain the steps to follow to configure this access:
- Access your server via SSH as the “root” user Additional information You can find more information about accessing your server via SSH in the article: Access Linux via SSH
-
You need to allow remote connections. To do so, follow these steps:
Note
Remember that before modifying the file, you need to replace:
- “xxx.xxx.xxx.xxx“ with the IP that will have access to the databases
Open the file with the command:
# nano /etc/mongod.confInside the file, bindIP will show the IP 127.0.0.1. We will also need to uncomment the port section and leave it in this format:
net: bindIp: 127.0.0.1,xxx.xxx.xxx.xxx port: 27017Once the file has been modified, we can restart the service:
# systemctl restart mongod -
We can confirm that it is serving on the public IP with the following command:
# ss state all sport = :27017 -
Finally, what you need to do is enable port 27017 in the client panel firewall. You need to create a rule like this:
Note
We recommend allowing only the IP addresses from which you will access the server, as otherwise you could have security issues with the server.
Remember, if you have questions about this or any other issue related to your servers at Clouding, feel free to write to soporte@clouding.ioWe are here for whatever you need. Get in touch!