DevOps Prerequisite (Part 2):Networking basics
Tags: devops
Published: 2023-03-17 07:15:54

Assume we have 2 devices A & B

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8hkjh9spld7zvnzj587.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gv9ua3aa8kjzmtawl0xf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gun8lpth89r0cejdog67.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5bc8oj6z74dxfct62pt.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pzoya93emd1xy9h8zb93.png)
Now they can communicate through switch

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/werklwin3tbhzprpvs4o.png)

Now assume we have 2 networks and 2 switches thus.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wa1h34snrzdo3bquo53.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85rsaezl15rsvfwk0x0l.png)
Since  the router connects 2 networks , it gets 2 IP addresses assigned to manage these 2 network.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cry1iuuwhiqa8rkjbe5g.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6m85sn4sbrf7man9r66.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76ek8sr3md5uinq3q19n.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqz1g8jls5fwqeez490u.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6bjwe7nvds2bser77lw.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1cg82dtkn5xmzhozeyy.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8m7gkfguw6xneubeax9u.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7rxin2peryd0ipi60qp.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/stc485oyozvphjp03qkk.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3muopfak0hhsi62bmikq.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yno60y4fb0bw5ogo5sfe.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2h69hgwib80jo55b77ao.png)
1 to connect to internet and other connect between 2 networks.


**Set up linux host as router**
Assume we have 3 hosts

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e1tgeosfcouidiy2nlxz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3opj3v3qxudgmu5qgxo.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8modq0g7ynbq3gq2ipj.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m06wmyc9b2w6tgh95dyy.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a6t0izjy4vfin6sub0un.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzzommuyr4hicdnxn8fq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4m6eyvqeb05354zuxz55.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exj2os79cezo07ya12zp.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g4oif9uk0rfxvdd2c63.png)
Now you can ping but can not see any output in screen. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpwtz6pjej3w5c7hx2r1.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kyd45l948y75m9hfv98d.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qoxdjsz4lk9h1v2xlz3.png)

Summary:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dr8qwkmsjaxcwt4eihj7.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08kge5zkgsdq4x5393xf.png)


for example

```
ssh appo1
```
then we will have the root permission

```
sudo -i
```
then we will appoint the ip address into the app

```
ip addr add <ip address> dev eth0
```
Then we can get out of the app01 and go to other app. For example

```
ssh app02
```
then the same process to appoint the ip address.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rsl2buprvkfy4pi1suf.png)


now,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgr5m3rrwp718uqnanyc.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6p9pu23e1xkpvd55ovd.png)


**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zd830salas1clul5flx8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mfhm0xp7kucnkq9zkhw.png)


Domain structure:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06nokmcruuq5ihi0v5i3.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kzrxgtewfnzdgzretl2z.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46zkuvj6278u2rby59kh.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zs8fr9mvu50dn4zaa6a.png)
Moreover, you can look up for any website. which is present in your server (using nslookup & dig)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc9q3e80krvq4ozrykkq.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2md4xmik77q2msxmbkuf.png)

Let's do a few labs:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm00igi0gi6x7l42iz1s.png)
We need to set search to mean yahoo.com . We need to do that in the /etc/resolv.config file

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rm3f3r8tkjzuc8rudlx9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/709fw011iiovphur2z9a.png)

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](https://kodekloud.com/lessons/networking-basics-2/)

We are done!

<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">

See you in an another blog 😉