Saturday, 27 May 2017

How to find out whether a host is in our network or not?

 

Have you ever thought why does your ISP (internet service provider) give you an IP address, subnet mask, default gateway IP address?. I am pretty sure you know why are you given an IP address but, most of the people don't know why you are given subnet mask and default gateway IP address.

Most of the time the IP address given to you is private IP address not public. That means if you search for that IP address on google you will not be able to ping it. If you google "what is my IP" you will find that it's different from the IP given by your ISP. The IP given by Google is your public IP address and the one provided by your ISP is your private IP address.


This IP address given to you by ISP is used to find the host within the local network not on the internet.
Now coming to the default gateway, it is used to give you a public identity. Whatever request you make to the Internet actually goes through your default router/gateway. On the internet, no one understands your private IP address. 

The only thing they know is your default gateway's IP address, so before moving out into the internet you change your IP address to that of default gateway's IP, and default gateway's identity becomes your identity.
We have discussed this in depth in NAT. 

Why do we use subnet mask?

Well by now you would have understood why do we need subnet mask, and Yes! you are right it is used to find out whether a host belongs to your network or not.
There are some simple series of steps followed to find out whether a host is on your network or not.
Consider the following scenario, where you have two nodes A and B.


Let's assume node A wants to send some message to node B. It checks whether node B is on its network or not. First, he performs a bitwise AND of his IP address with the subnet mask (Node A's subnet mask) and generates another IP address, let's call it P. Then he takes IP address of B and performs bitwise AND with the subnet mask (Node A's subnet mask) and generates one more IP address, let's call it Q.


As we found from the calculations that both P and Q are same. So according to node A both are on the same network. Remember this is according to A only not B. So this is how you find whether a host belongs to your network or not. 

Here is a question for you. Tell me in which scenario is this possible that, when B follows the same procedure it finds out that it is on a different network?

Hope this was helpful. Leave your questions, answers & suggestions in the comment section below. And make sure to like us on Facebook and follow on Google+.

Thank you!