How to Bind IP Address with Mongodb ubuntu 22.04 LTS


MongoDB, otherwise called Mongo, is an open-source report information base utilized usually in current web applications. As a matter of course, it just permits associations that start on a similar worker where it’s introduced. In the event that you need to oversee MongoDB distantly or associate it to a different application worker, there are a couple of changes you’d need to make to the default setup.

 

In this post, We will bind IP address with MongoDB to allow access from the network.

 

I believe, You have already installed MongoDB on ubuntu machine, If not click on given link to install mongoDB.

 

https://www.techbeginner.in/2020/03/how-to-install-mongodb-on-ubutnu-1604.html  

 

Step 1: Find the Local IP Addess 

 

You need to execute the following command to get local ip address to Bind with mongoDB.

ifconfig

You should get output like this.

Here you can find the local ip address of your machine, In my case i have 10.128.0.51 local ip addresss, We will bind this ip adress with MongoDB.

 

Step 2: Open MongoDB Config file

 

You need to open the mongod.conf file in your text editor, to bind local ip address in mongoDB by using following commands.

sudo vim  /etc/mongod.conf 

After that you need to go network config or just jump on line number 24

You need to use comma to bind with Network interfaces IP address.

 

Step 3: Restart the MongoDB 

 

Its time to restart the MongoDB service to get changes by following the given command.

sudo systemctl restart mongod

 

Step 4: Bind IP Verification

 

We can use the netstat command to get bind IP Adress with the MongoDB port 27017, execute the given command for the same.

netstat -plntu | grep 27017

If everything is good So then we will get the output like this.

Here we can see that our local IP address is bind with MongoDB port 27017, That means our configuration is working find.

 

Step 5: UFW Firewall Rule

 

As we can see that MongoDB is working with localhost and Machine Local/Public IP address, If we enabled any kind of firewall server So then  we need to open the mongoDB port, Use the following command for the same.

sudo ufw allow 27017


This is a default UFW firewall rules, if you want to more secure it So then you need to use a custom firewall configure.  

 

Conclusion
 

We have successfully bind Local IP Address with MongoDB server on ubuntu machine, Still you have any issue leave a comment.

How to Bind IP Address with Mongodb ubuntu 22.04 LTS

2 thoughts on “How to Bind IP Address with Mongodb ubuntu 22.04 LTS

  1. Hi,
    I can bind my local Ip to my MongoDB Server. However, I have a separate NodeJS server & I want to bind NodeJS server's ip to my MongoDB server. How can we bind an ip which is "Not a local ip"? Can you please guide.

    Regards,
    Fareed

  2. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top