Thursday, 18 August 2016

IP Address



IP Address
                Every computer in a network should have a unique IP address. An IP address is a 32 bit address, which is separated in to 4 octets. As each octet is having 8 bits, the maximum value of 8 bits will be 11111111(255 decimal value) and minimum 00000000(0). We can divide the IP address in to 2 parts. The network ID and the Client ID. The value of subnet mask determines these 2 parts. A subnet mask is also a 32 bit number that masks the IP address. We use the masking bit 1 to cover the network potion and 0 for the host addresses.

  

  
See the IP details of my machine. It is having an IP address of 192.168.109.1 and a subnet mask of 255.255.255.0. Let me put this as binary as below.

IP Address  :      11000000.10101000.01101101.00000001
Subnet Mask :    11111111.11111111.11111111.00000000
                              In my case the first 24 bits are masked and thus the value of first 24 bit in IP address represents my network ID. I.e. 192.168.109.0 is my network ID and I can use 192.168.109.1-192.168.109.254 for my computers in the network.

                            So we can choose the subnet mask depends on the number of clients needed in our network. Eg: if I want to accommodate 500 computers in my network, 111110100 is the binary value for 500 and that indicates 9 bits required for the clients and you can mask 32-9=23 bits for the subnet. So 11111111 11111111 11111110 00000000 will be the subnet mask, which will be 255.255.254.0 in decimal. 

                                    Subnet mask is used on every device to determine if a packet is local or outside the network. All the packets destined to outside network will be forwarded to the default gateway IP, which will be usually the router. All the computers in the same broadcast domain should have the same network ID. The computers uses ARP (Address Resolution Protocol) broadcast to get the destination computer’s MAC address in the same network.

   As shown in the diagram consider computer A wants to send a packet to computer B. All computers are configured with a subnet mask of 255.255.255.0 and hence 192.168.1.0 will be their network ID. As we learn earlier the packets should be encapsulated with the MAC to create the frame. But A doesn’t know the MAC address of B. So A sends an ARP broad cast asking for the MAC of a computer B with the IP 192.168.11. As it is with the broadcast MAC all the computers will receive the frame and when they check the IP portion only computer B will reply with its MAC and all others will discard it. Once A get the MAC it uses that for future packets to B to make a point to point communication. Consider A wants to send a packet to 20.30.4.5. By checking the IP address A will learn that the IP doesn’t belongs to its network and will use the MAC address of the Default gateway to forward the frame there.

 Public vs Private IP

            
                The IP addresses are further divided in to Private and public IP addresses. Public IP address is used in the internet and private IPs in the home office environments. Private IPs are not pass through the internet routers. The Public IPs are provided by Internet Assigned Numbers Authority (IANA) and they assigned Regional Internet Registries (RIRs) with different large blocks IPs and RIRs further allocate Blocks of IPs to different Internet Service Providers (ISP) and they assign the IPs to home or office connections. IANA gives the IPs with class license.



                                  There are 5 classes of IPs. They are classified based on the first octet of the IP. First one is the class A and the first octet starts with 1-126. They have a subnet mask of 255.0.0.0. So 126 networks and 224 host addresses in each network is possible in Class A. For class B first octet starts with 128-191 and have a subnet mask of 255.255.0.0. So 16,320 networks with 216 host addresses in each is possible in class B. The class C first octet starts with 192-223 and having subnet mask of 255.255.255.0. So 2,080,800 networks with 28 host addresses in each is possible. The class D starts with 224-240 and is used for multicasting. The remaining IPs are reserved. There is a special IP Starts with 127.0.0.0-127.255.255.255 called loopback address, which points to the same machine.


      The private IP address block is as follows
IP Address Range
Number of IPs
10.0.0.0-10.255.255.255
16,177,126
172.16.0.0-172.31.255.255
1,048,576
192.168.0.0-192.168.255.255
65,536
 

Dynamic Vs Static IP

              We can assign the IP address manually in each machine connected to a network. But as the network grows it will be difficult to assign IP manually. So we can setup a machine to supply the IP address to all connected devices. There is a protocol called Dynamic Host Configuration Protocol (DHCP) to accomplish this task. So each machine looks for a DHCP server when they boots up through a DHCP DISCOVER Broadcast. When a DHCP server receives a DHCPDISCOVER message from a client, which is an IP address lease request, the server reserves an IP address for the client and makes a lease offer by sending a DHCPOFFER message to the client. This message contains the client's MAC address, the IP address that the server is offering, the subnet mask, the lease duration, and the IP address of the DHCP server making the offer. In response to the DHCP offer, the client replies with a DHCP request, broadcast to the server, requesting the offered address. When the DHCP server receives the DHCPREQUEST message from the client, it sends the DHCPACK packet to the client. So the IP configured manually is static IP and the one obtained through DHCP is called as Dynamic IP.


                            If a machine is unable to find a DHCP server, it will be assigned an Automatic Private IP Addressing (APIPA) starting with 169.254.x.x . In that situations you have to  make sure your patch cords are perfectly plugged in or the switch in to which your machine is plugged in having connectivity to DHCP server like that. Sometimes the IP pool you assigned is full in the DHCP server, causes APIPA. If the DHCP server goes down, all the machine configured with dynamic IP will get the APIPA.  Another issue comes with DHCP is the rogue DHCP servers. Especially with the wireless access points  the DHCP is enable from the factory settings and if you plug it without disabling that, it will also offer IP to clients.


IPv6


                                  The IP address we discussed was able to serve 4 billion addresses. But the growth of the internet demands more than that and hence introduced a new addressing system called IPv6. The earlier one is known as IPv4. IPv6 is having 128 bits. It is represented in the hex decimal format, as 8 groups and 4hex in each. E.g. 002f:df52:dd34:0000:0000:f8ff:fe21:68de. We are using lot of abbreviations to represent the IPv6. The first step is to drop all leading 0 and if you have a group of four 0s, represent it by single 0. Thus our IP will become 2f:df52:dd34:0:0:f8ff:fe21:68de. Another thing we can do is replace long strings of 0 with:: . We can use this only at one place. So my IP will become represented as 2f:df52:dd34::f8ff:fe21:68de. 

                       0000:0000:0000:0000:0000:0000:0000:0001 is known as the loopback address in IPv6. We can abbreviate it in to 0:0:0:0:0:0:0:1 and finally to ::1.
 
 
 

No comments:

Post a Comment