Lets say that i want to connect to google. I will open a browser and type “www.google.com”. What happens here?. The google.com web application runs on the google dedicated network, the web application is hosted on a machine and can be accessed on a port. So how can our machine connect to google network and access the service.
This is where IP address comes into the picture. Every domain name like “google.com” will be converted to an IP address that the machine can understand and use that to send the request. An IP address is 32bit containing 2 parts, network ID and Host ID. Using the network ID, our request reaches the Google network and using Host ID, it reaches the host machine in that network where google web application is running.
How can we know the ip address of the domain name “google.com”. This is where Internet Service Provider (ISP) comes into picture. The ISP is a service provider that is responsible for providing a server called DNS ( Domain Name Service ). This service is running in our network. Before going directly to the google network, we will first ask DNS to provide the IP address of the Domain name “www.google.com”, which it will return. We will see how dns works in a different article.
Connecting to DNS server everytime is a time consuming. So we do a domain name query for the first time to the DNS server for a domain name and then once the results are back to the requested machine, the results are saved for some time for future reference. So once the results are available at the machine itself, we will not be touching the DNS service.
Lets understand the IP address. We already know that an IP address is 32bit, but why?. Initially when IPV4 was created they taught 32bit address will be sufficient to assign ip addresses to all systems. But now with increasing number of systems use in various areas, IPV6 was introduced.
IPV4 is a 32bit which means we can have 4,294,967,296 ip addresses in and IPV6 we can have 340 undecillion ip address which is very huge. IPV6 was created to overcome the shortage of ip address in IPV4.
As we already know the IP address is of 32bit. Which is divided into 2 parts which is a network ID and host ID. Initially they divided this 32 bits into a 2 static parts, 8 bits of network id and 24 bits of host id. So in this case i have 256 network ids (2^8) and 16 million hosts id (2^24). Clearly this is not feasible for future purpose with the increase of systems in many areas, so they came up with the Class system for Ip address.
In the class system, instead of dividing the network ID and Host ID they came up with different approach. The Entire IP address of 2^32, is divided into 4 parts of 8 bits. They have taken the first bit in the first 8 bits. So the first bit can be either a 0 or 1. So we have 2 parts which contain 2^31 ip address, since first bit is already taken
Now they have taken the second part which is 1. This has now 2^31 space. Now they again went with the second bit. The first bit has 0 and 1. The second bit has 1 and 0. This becomes 10 and 11 now with each of them having 2^30 space. Similarly they have taken the second part from the previous one which is 11 and again added a third bit which is 1 and 0. Now it becomes 110 and 111 parts. We have now 2 power 29 space.
Similarly they have taken the second part from the previous one which is 111 and again added a third bit which is 1 and 0. Now it becomes 1110 and 1111 parts. The first part which starts with 0 is class A, 10 is class B, 110 is Class C, 1110 is Class D and 1111 is class ERather than representing the ip address in 1 and 0, we came up with the dotted decimal representation. In this we divide the 32 bit into 4 equal bit of 8 bits and convert them to octal number so that we can easily remember. Hence we see the current ip addresses as 192.169.1.26 etc.
Let's see how Class A is represented. The Class A which is 32 bit, is divided into 2 parts 8 bit and 24 bit . in the first part of 8 bit, the first is set to 0 as you can see above which means now in the first part we have only 7 bits which is 2^7, 128 and in the second part we have 2^24 which is 16 million. This means we have 128 networks that can be created and each network have 16 million ip addresses that can be assigned to the Hosts.
So how can we know an ip address is Class A or not. In this case, the 8 bit is taken. The first bit is already 0 which means we have 127 left. In this network, the ip that starts with 0 is not taken and 127 is taken as loop back address. So we have range from 1-126 available now. By this we can say if any IP address that falls from 1 to 126 in the first octal is said to be class A address.
The Class B is divided into 2 parts again with 16 bit of network id and 16 bit of Host id. In the first 16 bit, 1 and 0 are taken the first positions leaving 2^14 available for network which is roughly 16k. The host ID can be 2^16 per network. So if we convert the network ID and Host ID into ranges we see range of class B from 128-191. If you see an Ip address with the first bit ranging between 128 to 191, it is a Class B ip address. similarly
192-223 - Class C
224-239 - Class D : Multicasting, broadcasting
240-255 - Class E : Reserved, Some time military applications
Subnet : Let's say we have a Class A Address space for us which means we have 16 million hosts that can be configured. The biggest problem here is the maintenance. It is very hard for an admin to manage these 16 million machines configured.
Let's say we have 4 departments in an office , IT, HR, Sales and Storage. When all of the machines that belong to these 4 groups are configured in one network, they can easily access other machines, because they are configured on the same network. There would be no security here which means people from the HR department can access data from machines that belong to Sales team which is a security breach. We have to divide the above big network into smaller networks which we call it as Subnet. This way we can restrict one subnetwork to access machine from other sub networks. For example, HR has a subnetwork and IT has another subnetwork. Machine from one network can't access machine belong to other network which provides security.
Let's take an example of Class C IP address which contains 8 bits in host part which means 256 ip address and 2^24 networks. Let's say that I bought the Class C IP address which is 200.1.2.0. Now since we can configure 256 host machines in this network, we will be doing a sub networks for better management. The Class C contains 24 bit network ID and 8 bit host ID. If we have to create 2 subnets with this we have to choose 1 bit ( first bit ) in the host ID leaving the network ID as it is. If we want to create 4 subnets we have to go for 2 bits ( first 2 bits ) in the 8 bit host ID leaving the network ID.
Now in the 200.1.2.(-------), we will create 2 subnets. Using the Host ID, we will create 2 subnets. As we already said if we have to create 2 subnets, we have to choose a single bit in the host ID.
So we have 0------- and 1------- in the first bit of the 8bits host ID. The subnet range of address in first half will be 0-127 ( 00000000 goes to 0) and the second half will be 128-256 (10000000 to 1111111 ). Now in the above case of 200.1.2.Host ID the first part 200.1.2. Is called network ID and rest is Host ID. Since we have taken the first bit in the Host ID, that first is used to define the subnet id also called as SID.When ever we do a subnet, we will also get an internal router which the routing of requests happen. The router is responsible for routing requests that are internal and also for requests that come from outside of the network ie. from internet.
One thing to remember her when using subnetting is that if we create 2 subnets for a Class C , we are only configuring 252 hosts of 256 which means, 2 of them are used as network Id for both subnets and 2 ip for broadcasting for both subnets.
But one Question over here is how can router identify which network does a particular IP exists?. Lets say I have created 4 subnets for the same Class C IP address 200.1.2.0. Now the 4 subnets will be divided and ip range exists from 0-63,64-127,128-191 and 192-254.
Now if a request comes from the external world to a host in the whole network, how can the router know which subnetwork it has to pass the request?. So we need to identify the network ID for which this IP address belongs to. I.e if a request comes for 200.1.2.130, we need to find which subnetwork we need to pass this request. How does router figure it out?
Subnet mask is the number that helps in finding the network to which this ip address belong. A subnet mask is a 32bit number with 1s and 0s. 1s represent network ID and 0s represent Host Id. in 200.1.2.0, the network ID ( 200.1.2) is network ID which is 24bit and last is host ID part is 8 bit.
Now in this case, all the 24 bit will be 1s which represent network ID and rest 8 bit contains 0s representing host ID. but since we have created 4 subnets using first 2 bits of host ID, we have 1s in first 2 bits and rest with 0s, i.e
1111111.1111111.1111111.11000000 = 255.255.255.192
Now if we convert the ip address that we need for 200.1.2.130 and both AND with the subnet mask, 11001000.0000001.00000010.10111000
11111111.11111111.11111111.11000000 : 255.255.255.192
11001000.00000001.00000010.10011000 : 200.1.2.130
----------------------------------
11001000.00000001.00000010.10000000 : 200.1.2.128
200.1.2.128 is the network that this ip address belong to. That means that ip address belong to the range 128-192 ip address. For calculating these details, router uses the routing table to find out which network the incoming packet should send.
The routing table or routing information base (RIB) is a data table stored in a router or a network host that lists the routes to particular network destinations, ie routers using this table will find which network the request came for.
In the next article, we will see some more concepts of networking.
Good to see you Jagadesh, hope you are doing good...
ReplyDeleteThanks Bharath, Yeah busy these days. But will start blogging again.
Delete