Saturday 11 May 2013

understand IP adressing and subnetting



First of all let us understand IP? IP stands for Internet Protocol. It is a part of TCP/IP stack. IP is a layer 3 protocol according to OSI reference model. IP is mainly responsible for routing. The IP protocol uses specific address called IP address or logical address. Whenever you send any data to another system using any network based application, like internet explorer, FTP client or outlook express etc., the data travels from your network application to the TCP. TCP adds the relevant information to the data and hands it over to the IP. =================================================
 
The IP protocol here adds the source and destination IP address. Now let us discuss about IP address in detail.
===============================================
As you can see in the illustration, IP address is a 32 bit binary number. But for the ease of human reference it is being represented into dotted decimal notations.Actually it is the dotted decimal notation which is always assigned to the systems by network administrator. Then why do we need to understand the binary form? Definitely this question should arise in your mind. Well as a Cisco Certified Network Associate, you may be required to perform complex tasks related to networking. One of the tasks may be to subnet the IP address. I know now you will be thinking about subnetting. Well here all I can tell you is that subnetting is a process of dividing one network into multiple smaller networks. Let us get back to our core topic. That is, what is IP address? As we discussed earlier, it's a layer three or logical address used by IP protocol to determine whereabouts of the destination system and the exact system itself. Let us delve into further details.
=================================================
As I told you that IP address is a 32 bit binary numbers, which identifies to which logical group the computer belongs to and the exact host. In other words, IP address constitutes of two parts. One part of the address identifies the logical group or network ID of the computer and the other part represents the host itself.Here in the illustration, up to "192.168.0" is network portion and "1" is the host portion of the address. In other words the computer which is assigned with an IP address of 192.168.0.1 belongs to 192.168.0.0 network and its unique identification is "1". Now the important question is how it is decided that how much portion of the IP address is network address and how much is the host ID? If you look at the binary format of the example IP address, you will find the answer. All continuous "1's" in the subnet mask decides the network portion of the IP address. The portion of IP address above all continuous ones in subnet mask represents network address. The portion of IP address above all remaining zeroes represents host ID.
===================================================
Here you can see that PC-1 and PC-2 are in 192.168.0.0 network. Since both of the computers are sharing the common network id, i.e., 192.168.0, we can call them to be belonging to same logical group. The computers belonging to same logical group can communicate with each other directly without the help of any intermediate device like routers. At the other side PC-3 and PC-4 are in other logical group which is 192.168.1.0. Here PC-3 and PC-4 both share the same network portion, i.e., 192.168.1 and there host ID's are unique in their network. Remember, in the world of networking, it is not the physical layout which makes different networks, but it is the layer three addresses or logical address which divides computers into different networks. In the illustration if we assign all of the four computers the same network id, i.e., 192.168.0.0 then all of them will become a single network and we will not require a device like router in between. Computers in the same network can communicate with each other without any third device. But computers with different network id must have some type of router in between to act as gateway for the computers of the two networks.
==================================================
Suppose here in the diagram if PC-1 wants to send a data packet to PC-2, what will happen? At PC-1 the IP protocol will put its own IP address as source address, PC-2's IP address as destination IP address in the data packet. While a source and destination layer three addresses are being added to the data packet by say IP protocol, the IP protocol decides whether the packet is destined for the same network or to other network than its own. If the destination network is same then it knows that there is no requirement of any gateway address. It will simply send an ARP broadcast to its own network, asking for the MAC address of the destination machine i.e., PC-2. ARP stands for Address Resolution Protocol and it is a part of the TCP/IP protocol stack. ARP is used to resolve the MAC address from the known IP address. Here in our case the layer three components know what the destination IP address is. But it does not know the MAC address of the computer who's IP address is 192.168.0.2. So in order to know the destination machines MAC address without which data cannot be moved out of the machine, PC-1 sends ARP broadcast to its own network, asking for the MAC address of the PC-2. The broadcast means request destined for all computers.
===================================================
Here in our case the ARP broadcast will be looking something like this. You can see that PC-1 is sending an ARP broadcast to entire network. Entire network here is specified by 255 which is the maximum value for the host portion. Just have a look over the Destination IP address 192.168.0.255. i.e., the packet is destined for the every computer whose Network ID is 192.168.0. This broadcast packet will reach to every computer at the routers E0 side. But the router will not allow this broadcast to be propagated to other side of the router. The ARP broadcast contains a request asking for PC-2's MAC address. In the last line you can see that PC-2 is responding with its MAC address. This is how computers learn about destination computers MAC address. Then layer two protocols like Ethernet put this address as destination MAC address before data is finally being sent out of the computer. So this whole process was related to the communication between computers in same network. What will happen if PC-1 wanted to communicate with PC-3?
============================================== ====
In the case of PC-1 wanted to communicate with PC-3, the Layer three protocols will discover that the destination computer is in other network and it can't get MAC address of the destination computer directly. Because a computer cannot broadcast any thing other than its own network. And when the router will receive a broadcast destined for 192.168.0.0 network, it will simply drop it. So once PC-1 decided that the destination is in other network, it knows there must be some kind of router in between, and instead of asking for the MAC address of the destination Machine in the ARP broadcast, it should ask for the MAC address of the router. So now in this case PC-1 will send a broadcast to its own network, but instead of asking for the MAC address of the destination computer, it is asking who is having 192.168.0.3? which is the routers address to which side the PC-1's network is connected. The router is replying with its own MAC address to the PC-1. Once PC-1 obtains the PC-3's MAC address, it will send the packet on the network. Now this packet will be received by the router, Since the packet's destination MAC address will match with the router's MAC address. Now router will check the received packets destination layer three network ID and it will find that the destination network is directly connected to it on Port E1. So router will send an ARP broadcast on E1 destined for the network 192.168.1.255 asking for the MAC address of 192.168.1.1. PC-3 will send its MAC address to the router and router will add that MAC address to the packets destination layer two address field and forward it to the E1 interface. So you would have understood how layer three protocols like IP are used to divide computers into different logical groups. You also understood that routers do not forward broadcasts to other side. Actually we will discuss routing in later chapters. Let us get back to the current topic that is IP addressing.
===================================================
First of all let us get familiar with little of background. The TCP/IP protocols were initially developed as part of the research network developed by the United States Defense Advanced Research Projects Agency (DARPA or ARPA) in the 1970s by pioneering network engineers Vinton Cerf and Bob Kahn. The Designers of the IP protocols created 5 classes of the IP addresses. Namely class A, class B, class C, class D and class E.
==================================================
Class A is having first 8 bits reserved for network addressing and remaining 24 bits for host addressing. Hence it is having a default subnet mask of 255.0.0.0. Its decimal address range is from 1-126. Network 127.0.0.0 in class A is reserved for loop back address. Loop back address like 127.0.0.1 is used by all operating systems to identify itself. If you successfully ping to this address, it means the TCP/IP protocol is installed properly and it is functional. Class B is having first 16 bits reserved for network addressing and remaining 16 bits for host addressing. Hence it is having a default subnet mask of 255.255.0.0. Its decimal address range is from 128-191.
Class C is having first 24 bits reserved for network addressing and remaining 8 bits for host addressing. Hence it is having a default subnet mask of 255.255.255.0. Class D is reserved for multicasting and is in the range of 224-239. Class E is reserved for R&D purposes and is in the range of 240-255. Out of these five classes, only class A, B, and C are allowed to be used for commercial purposes. We cannot assign class D and E addresses to computers.
==================================================
According to the documentations of IP addressing, the first highest order bit in class A must remain "0", hence we actually get a network range of 2^7-2 equals to 126, i.e., from 1.0.0.0 to 126.0.0.0. and 2^24-2 equals to 16777214 hosts per network. For class B, the first highest order bit must remain "on" and second "off " that is binary "10" which gives a total of 2^14-2 equals to 16382 networks, i.e., from 128.1.0.0 to 191.254.0.0 and 2^16-2 equals to 65534 hosts per network. For class C, the first and second highest order bit must remain "on" and the third highest order bit "off" that is binary "110" which gives a total of 2^21-2 equals to 2097150 networks, i.e., from 192.0.1.0 to 223.255.254.0 and 2^8 -2 equals to 254 hosts per network. Here you might be thinking why I am subtracting 2 from either number of networks or number of hosts. Well that's a genuine doubt. Again according to IP documentation all the network bits cannot be either on or off at the same time so we have to subtract two combinations of all zeros and all ones. The same rule applies to host addressing as well so all the host bits cannot be turned on or off at the same time, hence minus two. In the case of hosts, all host bits turned "on" represent a broadcast address and all host bits turned off represent a network address. We cannot assign broadcast address as well as network address to hosts so we have to minus it.
Since all the class A addresses were being assigned to the universities and military organizations in the early days itself, the class A is not available for the public. Almost all class B addresses are also exhausted. Only some of the class C addresses are available. Earlier 2^32 IP addresses were considered quite a large number ...!! That's what was thought by the developers of IP protocol like DoD. When the TCP/IP protocol was developed at DoD, only few computers were there in the universities and other organizations. And not all of them were thinking to connect with each other. So 2^32 really seemed a big number those days. But with the advent of time the popularity of TCP/IP protocol started to soar. Almost every one wanted to be connected and hence every computer required one IP address in order to connect to others, and no more than one computer connected together can use the same IP address. Soon it was realized that in near future the IP address is going to be scarce. So the Scientists came up with a solution to do away with the shortage of IP address.
==================================================
They kept aside some of the IP addresses from all of the three classes namely class A, B, and C to be used as Private IP addresses. The remaining IP addresses in the above mentioned three classes were reserved to be used on internet and termed as Public IP address. The important thing to remember is that the computers having any IP address within these private ranges cannot connect to internet directly without some sort of network address translation. We will discuss network address translation later. The computers having addresses between these private ranges cannot connect to the internet directly due to the fact that the internet routers are configured to not forward the data packets destined for these private IP addresses. In other words if an internet router receives a packet destined for Private IP address, it will simply drop the packet. And this is implemented to save the IP addresses. You would be wondering how keeping aside some of the IP addresses as private addresses save the overall public IP addresses..? in fact it seems to be decreasing the number of public IP addresses.
==================================================
Just look at the network and you can yourself figure out how keeping few IP addresses as private saves lot of IP addresses. Here you see a private network comprising of lot of desktop computers is connected to internet through a server which is doing Network Address Translation. The server is having two network adapter cards with two IP addresses. The server's internal network card is having the IP address within the same Private network as that of Desktop computers. While server's external network interface card is having a public IP address 202.60.23.1. Using this public IP address, server is connected to internet. All the desktop computers are configured with a gateway as 192.168.0.100. Whenever any desktop computer want to connect to the internet, they simply send the data to NAT server, the server removes the source IP address from the clients packet and replaces it by its own public IP address, then forwards it to the internet. Though all the internal hosts having private IP addresses can connect to internet, but the IP addresses which will be going out as source addresses will be that of NAT server, that is 202.60.23.1. When replies come from the internet for the internal hosts, the NAT server hands over the data packets to the appropriate hosts. This is how thousands of computers in a company having private IP addresses can connect to internet using only single public IP address. Since Packets destined for private IP addresses gets discarded by internet routers, end number of organizations or companies can use the same private IP addresses internally and they will require only single public IP address. So definitely division of IP addresses into Public and Private saves a lot of IP addresses. Private IP addresses also provide a kind of security to the companies, since all the internal hosts having private IP addresses are represented by a single Public IP address. Only that single public IP address remains visible to internet. Though a lot of Public IP addresses are being saved due to private IP addresses but still large numbers of IP addresses are being wasted due to certain reasons. How still the IP addresses are being wasted, I will explain you. ======================================================
Just have a close look at the network. You can see several internet routers with two end networks attached. The very important thing you will notice in this exhibit is that every internet router's directly connected interfaces are consuming complete one network. See the connection between Router-B and Router-C, Router-B is having 202.10.3.1 and Router-C is having an IP address of 202.10.3.2 both in the class-C. Out of 254 IP addresses available in the Class-C network, only two IP addresses are being used between Router-B and Router-C. The remaining 252 IP addresses cannot be used anywhere else now, since same network cannot be assigned at multiple sides of the routers. Due to this rule a lot of IP addresses are being wasted between router to router connections. Lot of IP addresses are getting lost at network-1 and network-2 as well. You see that network-1 requires only 20 IP addresses and network-2 requires only 30 IP addresses, the remaining IP addresses at network-1 and network-2 cannot be used any where else, again causing a loss of lot of IP addresses. To save the IP addresses further getting lost this way, a new workaround was done, known as subnetting. Subnetting not only saves the IP addresses, but it also provides better management of the network. In simple words, subnetting is a process of dividing one large network into multiple smaller sub-networks. Just remember that in the network in front of you, lot of IP addresses were getting wasted due to the very less number of IP addresses required on the router interfaces than the number of IP addresses available in each Class-C network. So now we can divide one network into multiple smaller networks and those smaller networks can be assigned at different interfaces of the routers. In the present scenario, we are using almost five (5) class-C networks. This provides almost 254*5 equals to 1270 IP address. And how many addresses are we using? Only 58? So we are using only 58 IP addresses out of total 1270. How many IP addresses are getting wasted? 1270-58 is equal to 1212 IP addresses. So you can see that we are losing almost 1212 IP addresses which cannot be assigned any where else. The solution? Just divide the networks into smaller ones and save lot of IP addresses. Now how those networks can be divided... I will teach you in a moment.


Subnetting: 

To divide a large network into smaller sub-networks, we have to simply turn some of the host bits on in the subnet mask, thus increasing the number of sub-networks and decreasing the number of hosts per sub-networks. Here we are dividing a class C network into 2 smaller sub-networks by turning two host bits on in the subnet mask. It means now we are having 26 bits reserved for the network addressing and only 6 bits remaining for the host addressing. The formula to get the number of subnets is:
No. of subnets is equal to 2^n-2, where "n" is the number of bits taken from host. So here in our case we have taken 2 bits from the host, thus we get total of two subnets. In fact we get total of four subnets, but according to RFC which stands for Request For Comment and is the documentation of TCP/IP, we cannot use the first subnet because all the subnet bits are turned "off" in the first subnet and we cannot use the last subnet, because all the subnet bits are turned "on" at the same time, however Cisco routers does allow 1st subnet to be used by issuing an IOS command "ip subnet zero". Here just remember that the subnet bits refer to the number of bits taken from the host. So we have to subtract all subnet bits on and all subnet bits off. Practically we can use all the subnets, but from CCNA exam point of view we cannot use 1st and last subnet.
Now the No. of hosts per subnet is equal to 2^r -2, where "r" is the number of bits remaining for the host. So 2^r-2 is equal to 2^6-2 is equal to 62. So we get total of two subnets with 62 hosts per subnet. ==================================================
After getting the number of subnets and hosts per subnet, we have to find the valid host range in each subnet and network and broadcast address for each subnet. To get all these information, we have to get a block size. We get block size by subtracting decimal value of the subnet bits from the maximum value of the octet, that is 2^8 is equal to 256. So here Block size is equal to 256 - 192 = 64. In this case, 192 is the decimal value of the two subnet bits turned on. Once we get a block size, that block size becomes the network address of the first valid subnet. Add block size to the first valid subnet and it gives you the network address of the second subnet. Keep on adding the block size to next subnet until the value reaches to equal to all subnet bits turned "on", which is 192 in our case. So we cannot use this last subnet. So we got two valid subnets, i.e., subnet 64 and subnet 128. The valid IP range for the subnet 64 is from 192.168.0.65 to 192.168.0.126. The network address for this subnet is 192.168.0.64 and broadcast address is 192.168.0.127. We cannot assign these network and broadcast addresses to the system. The valid IP range for the subnet 128 is from 192.168.0.129 to 192.168.0.190. The network address for this subnet is 192.168.0.128 and the broadcast address is 192.168.0.191. =====================================================
First of all let us write the subnet mask. Since it is class C address, the default subnet mask length is 24 bits. And we have taken 3 bits extra from the host portion. Now we have total of 27 bits for network addressing. If you remember earlier lessons, you will be able to calculate that up-to 24 bits continuous "on" in subnet mask will be represented as 255.255.255.0, but we have taken 3 bits extra from the fourth octet. So the decimal value of the three bits from the left will be 224. Hence new subnet mask for the network 202.10.4.0/27 will be 255.255.255.224. It's important to remember that all the subnets will have the same subnet mask. Now let us calculate the number of subnets. Here the number of subnets =2^n-2 = 2^3-2 = 6. So we got six smaller networks or subnets out of dividing a single class C network. Now let us calculate the number of hosts per subnet. ==================================================
The number of hosts per subnet = 2^r-2 = 2^5-2 = 30. So we divided one big network into six smaller sub networks with 30 hosts each. Next let us calculate the block size. Block size = 256 - 224 =32. Here 224 is the decimal value of the subnet bits i.e., the number of bits we have taken from the host. Now start from the block size and keep on adding itself to next block till it reaches to maximum i.e., 224 which we cannot use. So we got the blocks of 32, 64, 96, 128, 160 and 192. The valid IP address in first subnet starts from 202.10.4.33 to 202.10.4.62, the network address for this subnet 32 is 202.10.4.32 and the broadcast address 202.10.4.63. The valid IP addresses in subnet 64 starts from 202.10.4.65 to 202.10.4.94, the network address for this subnet is 202.10.4.64 and the broadcast address is 202.10.4.95. The valid IP addresses in subnet 96 starts from 202.10.4.97 to 202.10.4.126, the network address for this subnet is 202.10.4.96 and the broadcast address is 202.10.4.127. The valid IP addresses in subnet 128 starts from 202.10.4.129 to 202.10.4.158, the network address for this subnet is 202.10.4.128 and the broadcast address is 202.10.4.159. The valid IP addresses for the subnet 160 are from 202.10.4.161 to 202.10.4.190, the network address is 202.10.4.160 and the broadcast address is 202.10.4.191. The valid IP addresses for the subnet 192 starts from 202.10.4.193 to 202.10.4.222, the network address for this subnet is 202.10.4.192 and the broadcast address is 202.10.4.223. ==================================================
Now you can see that we have divided single class c network into six sub-networks. And we are using five subnets out of six on different interfaces of the router. Every sub net is having the same subnet mask that is /27. If you remember earlier IP address assignment, we were losing almost 1212 IP addresses out of 1270. Now after sub-netting, we are saving almost 4*254=1016+30= 1046 IP addresses. Well that's really a huge saving.
Definitely we are able to save lot of IP addresses in the example but you can observe that we are still losing a lot of IP addresses. We know that on the network-1 and network-2 side, we may use all the IP addresses in the subnet, but what about router to router interfaces..? We are never going to use more than two IP address on the point to point serial link between two routers. So if our sub-networks are having 30 hosts each, we are utilizing only two IP addresses per subnet out of 30. Again we are losing almost 28 IP addresses per router to router interfaces. To save IP addresses which are being wasted this way, we use a concept called VLSM or classless routing. VLSM stands for Variable Length Subnet Mask. In classless routing we assign variable length subnet mask to different interfaces of the routers. The contrary of the classless routing is class full routing where every interface of the routers are having same subnet mask. By using classless routing we use different subnet mask for the router to router interfaces and some other subnet mask for the hosts side. ====================================================
Now you can see that we are using different subnet mask for the router to router interfaces and router to host interfaces. For router to router interfaces we are using slash 30 subnet masks, which provides only two IP addresses per subnet while the router to hosts side we are using slash 27 which is providing 30 hosts per subnet.
Now let us subnet a class B network.
===================================================
We have a requirement of total of 13 subnets with minimum of 4000 hosts per subnet. We are using the class B network 131.100.0.0. How many bits should we take from host portion to fulfill the above requirements? If we take two bits, we will be getting 2^2-2= 2 subnets. But we need 13 subnets. So if we take 5 bits then we will get 2^5-2=30 subnets. Great we are getting more than what we needed. But what about hosts. Just let us calculate. Since it is a class B network, the total number of host bits is 16, out of which we have taken 5 bits for sub-netting. So the number of hosts per subnet will be 2^11-2=2046. But we require at least 4000 hosts per subnet. So let us try once again. If we take 4 bits from hosts then? Let's calculate. ===================================================
If we take four bits from host portion, then total number of network bits becomes 20. The new subnet mask for each subnet will be 255.255.240.0. Number of subnets = 14 and number of hosts/subnet we get 4094. Exactly what we needed. So four bits extra solves our problem. One more important thing you should know that the representation of network addresses like 131.100.0.0/20 is referred as CIDR notation. CIDR stands for classless inter-domain routing.
Now we are going to discuss another important term related to IP addressing, "Super-netting". You will be wondering what is this new term? Very simple, remember what is sub netting? Division of one large network into multiple smaller sub-networks. And super-netting? Grouping multiple networks into larger super networks. Confused. We discussed that sub-netting is done to save the IP addresses, so super-netting is contrary to that, it will waste IP addresses, if use on client side. So why do we need super-netting? Well it is used by ISP's for route summarization. We do route summarization to bring down the number of routing table entry in the internet routers. As you should know that internet routers must have every network route entry into its routing table, in order to route packets to every possible destination. Routers simply drop packets if they don't find the destination network in the routing table. So internet routers will have to maintain routing table entry of every possible network around the world in order to provide connectivity from any where around the world to any site. This will lead to hundreds of thousands of routing table entry. The result of so many routing table entry will be slowed down routing performance, since routers will have to read through the very long list of routing table to find out the destination network before it can forward the data packets on outbound interface. Hence to reduce the number of routing table entry the ISP's gets assigned a large pool of IP addresses as super-nets. ===================================================
Here you can see in the illustration, a large ISP has got 202.100.100.0/22 super-net assigned. The large ISP is assigning small networks within the super-net to small ISP's. The small ISP's are further dividing the networks into sub-nets and then assigning to the customers. Important thing to notice here is that all the networks including sub-nets under the large ISP is represented as single super-net 202.100.100.0/22 to the internet. When ever any data packets arrive to the internet router for any small ISP's customers, the internet router will simply send to the Large ISP. Internet routers will have to remember only large ISP's network and not every network under the large ISP; hence super-netting effectively solves the problem of large number of routing table entry into the internet routers. Representation of large number of networks as single super-net into the internet routers routing table is referred as route summarization, and the representation of super-nets in the form of 202.100.100.0/22 is referred as CIDR notation. CIDR stands for class less inter domain routing. So we learnt how super-netting brings down the number of routing table entry into the internet routers. Now we will learn how to create super-nets. ===================================================
Remember, for sub-netting, we take bits from host, but for super-netting we give bits to hosts. Just see the figures. We had a class C network 202.100.100.0/24 but we removed two bits from the network portion and added to host. Here removing means turning the network bits off. If you examine the figures closely, you will find that each super-net here is a combination of four class C networks. The first super-net is ranging from 202.100.100.0 - 202.100.103.255, which includes network 202.100.100.0, network 202.100.101.0, network 202.100.102.0, and 202.100.103.0. The same way every super-net out here consists of four class C networks with 1022 hosts per supernet.

No comments:

Post a Comment