Basic Networking Concepts using Linux (PART-III)

Mounika Avirineni
DevOps Engineering on Cloud
5 min readJan 28, 2023
Networking in Linux

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
Check the options related to MongoDB

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 
Private IP address

Now let's start connecting to MongoDB using localhost

mongo --host localhost
Connecting using localhost

Now exit and try to connect MongoDB with a private IP address, To connect use the command

mongo --host private ip address
connecting using a 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

Updated the config file

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
Updating the mongod file using the command

Now you can validate by using the command

cat /etc/mongod.conf
The updated value of bindIp

Now you can access MongoDB with either localhost or private IP DNS. Restart MongoDB before connecting.

sudo systemctl restart mongod 
Command to restart mongod

Now try to connect to MongoDB using a Private IP address. Type exit to exit from the connection.

Connected to MongoDB using a private IP address

Now try to connect to MongoDB using port 27017

telnet privateip 27017
Connecting using 27017 port with private IP address

Now let's try to connect with public IP address

telnet publicip 27017
connecting using 27017 port with public IP address

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

Trying to connect from an external source
Detailed explanation about managing MongoDB to run on Universal Ip

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.

select the instance

Now select the instance and click on security, and select the security groups

select security groups

After clicking on security groups edit the inbound rules

edit the inbound rules

Click on save rules. Now try to connect to Mongo DB from the external source

Try to connect 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.

Checking for Mongo clients in local

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
Installing Mongodb clients

Now you can validate using mongocli or by using telnet

telnet publicip 27017
Trying to connect from the external source
The detailed explanation about accessing Mongo DB

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.

selecting the instance

Select the instance and click on instance state and select terminate instance.

Instance termination process
Instance termination

Now select Terminate. And your system will be terminated, To validate check the instance state.

Validating the instance state
The detailed explanation about Terminating the instance

🙏🏼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

--

--