Assume we have 2 devices A & B
How to connect them?
We need to keep them under a same network. Here it is switch.
Here eth0 is used to connect our devices to the switch.
Assume the IP address for the switch is 192.168.1.0
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)
Now they can communicate through switch
Now assume we have 2 networks and 2 switches thus.
How can these 2 network communicate?
Here comes router to connect different networks.
Since the router connects 2 networks , it gets 2 IP addresses assigned to manage these 2 network.
Now assume device B wants to connect with device C but while checking the connection, you can not see any connection between them
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
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
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
The IP on internet might be different and there can be different ip addresses on internet
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.
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
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
For a complex network like this, we will do this:
1 to connect to internet and other connect between 2 networks.
Set up linux host as router
Assume we have 3 hosts
If we try to reach Host C from Host A, there will be no output
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
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:
Now you can ping but can not see any output in screen.
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.
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.
Summary:
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.
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.
now,
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.
Domain structure:
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.
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.
Your organizational DNS will now save this Google's IP so that it does not need to follow this whole process every time.
Moreover, you can look up for any website. which is present in your server (using nslookup & dig)
Let's do a few labs:
We need to set search to mean yahoo.com . We need to do that in the /etc/resolv.config file
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)