Basic Networking Concepts using Linux (PART-III)
In this article, you will learn about “Basic Networking Concepts Using Linux” with Hands-on scenarios. Continuation to the Part II
👨🏽💻🧑🏻💻For more ARTICLES, FOLLOW📍DevOps Engineering on Cloud
Let’s get started.
Run MongoDB on Universal IP Address
MongoDB is already set up in the ec2 instance which is recovered in PartII.
From PartII you can observe you can connect to the database with localhost, But you cannot connect to the database using public or private IP addresses.
🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link
Let's discuss running the MongoDB database on a universal IP address. To get the usage of MongoDB use the command
mongo --help
If you have a MongoDB client installed on a specific machine, you can specify the hostname using --host
.
Since you have MongoDB set up in this instance, specify the public or private IP DNS associated with this instance using --host.
To get the private IP DNS of the instance use command
hostname -f
Now let's start connecting to MongoDB using localhost
mongo --host localhost
Now exit and try to connect MongoDB with a private IP address, To connect use the command
mongo --host private ip address
Here you are able to connect to MongoDB with localhost, But unable to connect with a Private IP address. To fix this issue you need to update the configuration file.
To update the file using the editor option of your choice. To update the file use command
sudo vi /etc/mongod.conf
Now in this file change the bindIp: 127.0.0.1 to 0.0.0.0
Instead of using editors, you can use commands to change the bindIp
sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mongod.conf
Now you can validate by using the command
cat /etc/mongod.conf
Now you can access MongoDB with either localhost or private IP DNS. Restart MongoDB before connecting.
sudo systemctl restart mongod
Now try to connect to MongoDB using a Private IP address. Type exit to exit from the connection.
Now try to connect to MongoDB using port 27017
telnet privateip 27017
Now let's try to connect with public IP address
telnet publicip 27017
Now try to connect using the command
mongo --host public ip
Now come out of the server and try to connect from the local
telnet public ip 27017
You will be unable to connect to MongoDB from the external source even though MongoDB is running using universal IP 0.0.0.0
Update Security Group to access Mongo DB
To access MongoDB from an external source you need to update the security Group. select the ec2 instance on which MongoDB is running and update the security group.
Now select the instance and click on security, and select the security groups
After clicking on security groups edit the inbound rules
Click on save rules. Now try to connect to Mongo DB from the external source
To connect to the MongoDB database you need to have a mongo client, then only you will be able to connect to the MongoDB database.
So there is no Mongo client so you will not be able to connect to the database directly, so install the mongo client then you will be able to connect to the mongo DB database that is running on the remote machine.
command to install mongo client on ubuntu
sudo apt-get install mongodb-clients
Now you can validate using mongocli or by using telnet
telnet publicip 27017
Cleanup AWS EC2 Instance used to demo networking concepts
To terminate the ec2 instance go to aws console and select the ec2 instance used for demo.
Select the instance and click on instance state and select terminate instance.
Now select Terminate. And your system will be terminated, To validate check the instance state.
🙏🏼Thank you, for reading the article. If you find it valuable please follow our publication DevOps Engineering on Cloud
🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link
Thanks to Vamsi Penmetsa