DEV Community

Cover image for DevOps Prerequisite (Part 2):Networking basics
Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

DevOps Prerequisite (Part 2):Networking basics

Assume we have 2 devices A & B

Image description

How to connect them?
We need to keep them under a same network. Here it is switch.

Image description

Image description
Here eth0 is used to connect our devices to the switch.
Assume the IP address for the switch is 192.168.1.0

Image description
We can now connect them with the devices.
Now device A & B are connected to the switch But firstly we can assign our devices some IP address within the same network (192.168.1._/24)

Image description
Now they can communicate through switch

Image description

Now assume we have 2 networks and 2 switches thus.

Image description

How can these 2 network communicate?
Here comes router to connect different networks.

Image description
Since the router connects 2 networks , it gets 2 IP addresses assigned to manage these 2 network.

Image description

Now assume device B wants to connect with device C but while checking the connection, you can not see any connection between them

Image description

Image description

Now, we need to create door form Network 192.168.1.0 , so that it can go through that door(gateway) to the destination

To transfer data from device B to C,

data from device B will go through 192.168.1.1 (gateway/door) to the destination (192.168.2.0) where device C resides.

For this, we will use

Image description

You can now see the destination and the gateway,right!!

Now if Device C wants to send a packet to B, you need to add this to route table

Image description

Now the gateway is 192.168.2.1 and destination is 192.168.1.0 network where device B resides.

Now assume device C needs to connect to the internet (172.217.194.0)

then it will use the gateway 192.168.2.1 to reach to destination 172.217.194.0

Image description

The IP on internet might be different and there can be different ip addresses on internet

Image description

Thus we can set the destination as default (0.0.0.0) . It means that any IP address can be the destination but we will use our gateway to go there.

Image description

Look carefully we have set the destination as default and gateway is the same for device C

Now using the gateway 192.168.2.1, device C & D can connect with any ip

Image description

Image description

Also, while setting destination (0.0.0.0) to Gateway : this means that you don't need a gateway and you can communicate within your own network

Image description

For a complex network like this, we will do this:

Image description
1 to connect to internet and other connect between 2 networks.

Set up linux host as router
Assume we have 3 hosts

Image description

Image description

Image description

If we try to reach Host C from Host A, there will be no output

Image description

Image description

As they are not connected properly.

A is connected with B
B is connected with C
but A is not connected with C

But we can set the destination and gateway to solve it

Image description

Image description

Image description

Transfer data from A to C->Here the gateway is 192.168.1.6 and destination is 192.168.2.0 where device C resides.
Transfer data from C to A:

Image description
Now you can ping but can not see any output in screen.

Image description

BY default the package is not forwarded because the host can be private or public. As device A & C both are private here, we can let them forward packages.

BY default this file has the values set 0 and thus there is not packages forwarded. But we can set it to 1 and you can see packages forwarded.

Image description
as the value has been set to 1, now you can see pings.
We can also set it for rboots as well so that we don't need to change it all the times.

Image description

Summary:

Image description

This is the difference in linux hosts. You have to enable this and then you can see the pings

For example, if we have to appoint 4 apps some ip addresses, first we will ssh into the app.

Image description

for example

ssh appo1
Enter fullscreen mode Exit fullscreen mode

then we will have the root permission

sudo -i
Enter fullscreen mode Exit fullscreen mode

then we will appoint the ip address into the app

ip addr add <ip address> dev eth0
Enter fullscreen mode Exit fullscreen mode

Then we can get out of the app01 and go to other app. For example

ssh app02
Enter fullscreen mode Exit fullscreen mode

then the same process to appoint the ip address.

Image description

now,

Image description

Image description

DNS (Domain Name System) Basics
Basically setting an IP address to a name makes things easier for us.

for example, setting 172.87.12.1 to "db" . Now we can easily communicate with that IP without writing the whole IP. We just need to use db here.

So, in a small system, the host can save all of these in /etc/hosts file but if we have big system, we need to allocate a DNS server where we can keep all of these information of IP and their assigned names.

So, when someone calls with one of the names, the system first look into the /etc/hosts file and then DNS server if needed.

Image description

Image description

Domain structure:

Image description

now assume you want to go to apps.google.com and search in your own office's browser, this is how this request will proceed.

Image description

As your office don't know apps or google, it will forward the request to the Root DNS and once it founds .com DNS (where company related domains are stored), it will then find Google's DNS and proceed.

Image description
Your organizational DNS will now save this Google's IP so that it does not need to follow this whole process every time.

Image description
Moreover, you can look up for any website. which is present in your server (using nslookup & dig)

Image description

Image description

Let's do a few labs:

Image description
We need to set search to mean yahoo.com . We need to do that in the /etc/resolv.config file

Image description

Image description

This is only to reduce manual entry in the /etc/hosts file. To set any IP with a name, you can do it in the /etc/hosts file but to reduce this pain of manual adding, you can do these things like meaning all searching to yahoo.com etc in the /etc/resolv.config file.

You can do this course including labs from KodeKloud

We are done!

See you in an another blog 😉

Top comments (0)