How to access droplet using IP address

I have installed droplet(Ubuntu 18.4) and MongoDb. I can access db via studio 3t using SSH tunnel and it’s working. My PHP based web application is in different server. Now I planning to move MongoDb on droplet and I need to access it using IP address. How can I connect MongoDb using IP address from other server?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thanks for the reply.

Hi @anzalafs,

From your post, I assume you already have active users on your MongoDB installation,correct?

Let’s assume that’s correct, I think you have enabled it auth as well but let’s say you haven’t just for the sake of the answer.

Enable MongoDB Auth

Open your conf

vi /etc/mongod.conf

and add the following lines

    authorization: 'enabled'

This will tell mongodb that whenever it starts up next, it needs to enforce database access control using the roles you have already configured.

By default mongodb is configured to allow connections only from localhost. We need to allow remote connections. In the same config file, go to the network interfaces section and change the bindIp from to which means allow connections from all ip addresses.

# network interfaces
    port: 27017
    bindIp:   #default value is

Now save, exit the file and restart your MongoDB.

Open up network port

MongoDB uses port number 27017 for all connections by default. So let’s open up that port

ubuntu:~$ sudo iptables -A INPUT -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
ubuntu:~$ sudo iptables -A OUTPUT  -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

Test the remote connections

Test the connection like

mongo -u user1 -p user1password <your_server_ip>/sampledb

Regards, KDSys