Basic Networking Concepts using Linux (PART-II)

Mounika Avirineni
DevOps Engineering on Cloud
9 min readNov 26, 2022
Networking on Linux OS

In this article, you will learn about “Basic Networking Concepts Using Linux” with Hands-on scenarios. Continuation to the Part I

👨🏽‍💻🧑🏻‍💻For more ARTICLES, FOLLOW📍DevOps Engineering on Cloud

Let’s get started.

Understanding the Structure of IP Address

Ip addresses can be public, private, localhost or loopback. All these IP addresses can be the ipv4 address or the ipv6 address.

🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link

Let’s discuss ipv4 addresses.

ipv4 addresses have 4 sections, either ipv4 public address, an ipv4 private address, or a localhost ipv4 address.

These 4 sections are divided by dots.

For example :

public and private IP addresses of an instance

And also connect to the ec2 instance and try the command

ping localhost
127.0.0.1 ( localhost ipv4 address)

The highest numerical IPv4 address overall is 255.255.255.255.

ipv4 addresses can start with any number, and mostly ipv6 IP addresses start with numbers 172 (or) 192 or something similar to these numbers.

A detailed explanation of the structure of IP addresses

Overview of DNS Aliases for IP Addresses

Let's discuss the Domain names such as www.google.com, www.youtube.com, www.itversity.com, etc.., everything will be associated with IP addresses. But the IP addresses are hidden from us.

You interact with remote applications by Domain name or DNS Aliases. Connect to the ec2 instance and use the command ping www.google.com

Now you can see the IP address associated with “google.com”.

Any Domain or DNS aliases will be mapped to IP addresses under the hood. you can talk to the servers using the IP addresses only, but it is tough for you to remember these IP addresses to access the application, that's why you map a domain name to these IP addresses.

The IP address of the Domain name

In AWS there are a few things to remember about the IP addresses and corresponding DNS

In AWS you have two IP addresses public and private IP addresses, for private IP addresses you have private IP DNS and for public IP addresses you have public IP DNS.

IP Addresses and DNS

Observe that the private IP DNS is derived from the private ipv4 address, in a similar way the public IP DNS is derived from the public ipv4 address.

Now get into the ec2 instance and run the command “IP addr”, you will be able to see the private Ip address.

And coming to the hostnames, these are derived from the private IP addresses and configured from private IP DNS.

Private ipv4 Address and DNS Address
A detailed Explanation of DNS Aliases

Install Jupyter Lab on Ubuntu

To install jupyter lab in the ec2 instance use pip from python. By default pip is not available in the ec2 instance, you have to install it.

 python3 -m pip jupyterlab
check whether the pip is available

So from the above output, you have known that the pip is not available. So you have to install pip. Before installing pip update the apt list using the command

sudo apt update
updating the apt list

After updating, install pip using the command

sudo apt install python3-pip
pip installation command

Now the python3-pip module is installed, so now you can install jupyterlab.

To install jupyter lab use the command

python3 -m pip install jupyterlab 
The command to install jupyter lab

To access the jupyter lab use command

jupyter lab

The jupyter lab is throwing an error, so exit and login back to the instance and try the command jupyter lab .

Accessing the jupyter lab

Here observe the jupyter lab is running on port 8888.

Jupyter lab running on localhost:8888

Sometimes even after re-login, it might throw an error because of version compatibility. Troubleshoot this error using the command

python3 -m pip install --user --upgrade aws-sam-cli

Now open another terminal and connect to the same ec2 instance using the ssh command.

Using another duplicate terminal

Now try telnet to verify the connection to jupyter lab, jupyter lab is running on port 8888.

telnet localhost 8888
Connected using telnet

If you stop the jupyter lab, Then you will not be connected using telnet.

Interrupted the jupyter lab
Connection refused using telnet
A detailed explanation of installing jupyter lab and accessing jupyter lab.

Run Jupyter Lab using Localhost

Commands to start Jupyter lab

jupyter lab

With this command, you can start jupyterlab on the localhost

Starting Jupyter lab

To see all the options related to jupyter lab use the command

jupyter lab --help
jupyter lab subcommands

Here jupyter lab is started on localhost with port number 8888, When it is running on localhost with port 8888 you cannot access this jupyter lab from the external world.

You can only access this from the ec2 instance itself, To verify this let's take another duplicate instance and try to connect with jupyter lab.

Connecting to jupyter lab using local host

Now let's try to connect with public ipv4 and private ipv4 addresses.

Firstly let's try with a private ipv4 address, To get the private ipv4 address from the terminal use the command

hostname -f
private DNS address from the ec2 terminal
Trying to connect with a private IP address

Now let's try to access this application (jupyterlab) using public IP address.

Trying to connect using a public ipv4 address

Here you are able to access the application only using localhost, and unable to access using either private or public IP address even though the application is running.

Now let's discuss the option to connect to jupyterlab using public and private ipv4 addresses.

To exit from the jupyterlab application use ctrl+c to quit.

To explore the options related to jupyter lab — — help,

To explore the options related to the jupyter lab

You can customize the IP address using — — IP, <unicode> you can give the private IP address or you can give the universal IP address 0.0.0.0.

If you use 0.0.0.0 the application will be bound to all the IP addresses associated with this machine.

So if you want to access the application using localhost or a private or public IP address, you have to use a universal IP address [0.0.0.0]. for that use the command

jupyter lab --ip 0.0.0.0
Jupyter lab command

Now it is bound to the private IP and loopback IP.

Let's try to validate it by connecting with localhost, private, and public IP address.

connecting with localhost
connecting with private IP address
connecting with public IP address

Now you can only access the application with localhost, public IP, and private IP. Still cannot access it from the external world, because the security group is not open for port 8888.

A detailed explanation about accessing jupyter lab

Update Security Group to access Jupyter Lab

Let's update the security group to access jupyter lab from the external world.

To update the security group, Go to the ec2 management console and select the ec2 instance that you are using currently for the jupyterlab demonstration and choose security, And then select security groups.

To edit the inbound rules

Select security groups, And you will be directed to another page, Select Edit inbound rules. and click on Add rule.

Updating the inbound rules
Add the rules

Now click on add rule, give the port range as 8888 and the source as My IP.

By selecting My IP you can access jupyter lab which is running on the ec2 instance, You can access jupyter lab only from your system where the IP address is mapped. From other systems, you cannot access jupyter lab.

Now click on Save rules.

Now try to connect using http://public IP address:8888

Accessing jupyter lab

Now paste the token to access the jupyter lab.

Find the token where the jupyter lab started.

Copying the token

Now paste the token and click on Login.

Jupyter lab

You can also check from the terminal. exit from the remote and check in the local.

Accessing the application from the local system
A detailed explanation about accessing jupyter lab from the external world

Setup Mongo DB on AWS EC2 Instance

To install Mongo DB, Search on google.com.

Mongo DB installation steps

You can follow the commands to install mongo DB on ubuntu 20.04

step -1


curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add
output for the first step to install Mongo DB

step -2

apt-key list
Output for the second step to install Mongo DB

step -3

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Output for the third step to install Mongo DB

step-4

sudo apt update
output for the fourth step to install Mongo DB

step -5

sudo apt install mongodb-org
Output for the fifth step to install Mongo DB

step -6

sudo systemctl start mongod.service
sudo systemctl status mongod
Command to check the Status of Mongo db

With these commands, you can install mango DB, if any error occurs during installing mango DB, use commands.

echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list

sudo apt-get update
sudo apt-get install libssl1.1

Then later use the command

sudo apt install mongodb-org

And then use this command, which deletes the focal-security list file you just created:

sudo rm /etc/apt/sources.list.d/focal-security.list

To review the details about the mongo DB use command

cat /etc/mongod.conf
Mongo DB config file

Here the Mondo DB is working on port 27017 and it is bonded to IP 127.0.0.1

Now let's try to connect to MongoDB using telnet.

telnet localhost 27017
trying to connect with localhost to Mongo DB

Now let's try to connect with a private IP address.

telnet private ip 27017
Trying to connect to Mongo DB using private ip

Now let's try with a public IP address

telnet public ip 27017
Trying to connect to Mongo DB using Public IP

So you are able to connect to the database with localhost, But you are unable to connect to the database using public or private IP addresses.

A detailed explanation of setting up Mongo DB on the ec2 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

Thank you Vamsi Penmetsa

--

--