Basic Networking Concepts using Linux (PART-II)
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 :
And also connect to the ec2 instance and try the command
ping localhost
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.
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.
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.
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.
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
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
After updating, install pip using the command
sudo apt install python3-pip
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
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
.
Here observe the jupyter lab is running on port 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.
Now try telnet to verify the connection to jupyter lab, jupyter lab is running on port 8888.
telnet localhost 8888
If you stop the jupyter lab, Then you will not be connected using telnet.
Run Jupyter Lab using Localhost
Commands to start Jupyter lab
jupyter lab
With this command, you can start jupyterlab on the localhost
To see all the options related to jupyter lab use the command
jupyter lab --help
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.
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
Now let's try to access this application (jupyterlab) using public IP 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,
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
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.
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.
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.
Select security groups, And you will be directed to another page, Select Edit inbound rules. and click on Add rule.
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
Now paste the token to access the jupyter lab.
Find the token where the jupyter lab started.
Now paste the token and click on Login.
You can also check from the terminal. exit from the remote and check in the local.
Setup Mongo DB on AWS EC2 Instance
To install Mongo DB, Search on google.com.
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
step -2
apt-key list
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
step-4
sudo apt update
step -5
sudo apt install mongodb-org
step -6
sudo systemctl start mongod.service
sudo systemctl status mongod
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
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
Now let's try to connect with a private IP address.
telnet private ip 27017
Now let's try with a public IP address
telnet public ip 27017
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.
🙏🏼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