Title:: Write A Program To Demonstrate Subnetting and Find The Subnet Masks
Title:: Write A Program To Demonstrate Subnetting and Find The Subnet Masks
Title: Lab Assignment on Unit V: Write a program to demonstrate subnetting and find
the subnet masks.
Date:-
Marks:- Signature:-
Title: Write a program to demonstrate subletting and find the subnet masks.
OBJECTIVES:
Problem Statement: Write a program to demonstrate subnetting and find the subnet masks.
Theory:
Internet Protocol being a layer-3 protocol (OSI) takes data Segments from layer-4 (Transport)
and divides it into packets. IP packet encapsulates data unit received from above layer and add to
its own header information.
IP header includes many relevant information including Version Number, which, in this context,
is 4. Other details are as follows:
Version: Version no. of Internet Protocol used (e.g. IPv4).
IHL: Internet Header Length; Length of entire IP header.
DSCP: Differentiated Services Code Point; this is Type of Service.
ECN: Explicit Congestion Notification; It carries information about the congestion seen in the
route.
Total Length: Length of entire IP Packet (including IP header and IP Payload).
Identification: If IP packet is fragmented during the transmission, all the fragments contain
same identification number. to identify original IP packet they belong to.
Flags: As required by the network resources, if IP Packet is too large to handle, these ‘flags’
tells if they can be fragmented or not. In this 3-bit flag, the MSB is always set to ‘0’.
Fragment Offset: This offset tells the exact position of the fragment in the original IP Packet.
Time to Live: To avoid looping in the network, every packet is sent with some TTL value set,
which tells the network how many routers (hops) this packet can cross. At each hop, its value is
decremented by one and when the value reaches zero, the packet is discarded.
Protocol: Tells the Network layer at the destination host, to which Protocol this packet belongs
to, i.e. the next level Protocol. For example protocol number of ICMP is 1, TCP is 6 and UDP is
17.
Header Checksum: This field is used to keep checksum value of entire header which is then
used to check if the packet is received error-free.
Source Address: 32-bit address of the Sender (or source) of the packet.
Destination Address: 32-bit address of the Receiver (or destination)
of the packet.
Options: This is optional field, which is used if the value of IHL is greater than 5. These
options may contain values for options such as Security, Record Route, Time Stamp, etc.
IPv4 supports three different types of addressing modes.:
Subnet Mask
The 32-bit IP address contains information about the host and its network. It is very necessary to
distinguish both. For this, routers use Subnet Mask, which is as long as the size of the network
address in the IP address. Subnet Mask is also 32 bits long. If the IP address in binary is ANDed
with its Subnet Mask, the result yields the Network address. For example, say the IP Address is
192.168.1.152 and the Subnet Mask is 255.255.255.0 then:
This way the Subnet Mask helps extract the Network ID and the Host from an IP Address.
It can be identified now that 192.168.1.0 is the Network number and 192.168.1.152 is the
host on that network.
Binary Representation
The positional value method is the simplest form of converting binary from decimal value. IP
address is 32 bit value which is divided into 4 octets. A binary octet contains 8 bits and the value
of each bit can be determined by the position of bit value '1' in the octet.
Positional value of bits is determined by 2 raised to power (position – 1), that is the value of a bit
1 at position 6 is 2^(6-1) that is 2^5 that is 32. The total value of the octet is determined by
adding up the positional value of bits. The value of 11000000 is 128+64 = 192. Some examples
are shown in the table below:
The number of networks and the number of hosts per class can be derived by this formula:
When calculating hosts' IP addresses, 2 IP addresses are decreased because they cannot be
assigned to hosts, i.e. the first IP of a network is network number and the last IP is reserved for
Broadcast IP.
Class A Address
The first bit of the first octet is always set to 0 (zero). Thus the first octet ranges from 1 – 127,
i.e.
Class A addresses only include IP starting from 1.x.x.x to 126.x.x.x only. The IP range 127.x.x.x
is reserved for loopback IP addresses.
The default subnet mask for Class A IP address is 255.0.0.0 which implies that Class A
addressing can have 126 networks (27-2) and 16777214 hosts (224-2). Class A IP address format
is thus:
0NNNNNNN.HHHHHHHH.HHHHHHHH.HHHHHHHH
Class B Address
An IP address which belongs to class B has the first two bits in the first octet set to 10, i.e. Class
B IP Addresses range from 128.0.x.x to 191.255.x.x. The default subnet mask for Class B is
255.255.x.x. Class B has 16384 (214) Network addresses and 65534 (216-2) Host addresses.
Class B IP address format is:
10NNNNNN.NNNNNNNN.HHHHHHHH.HHHHHHHH
Class C Address
The first octet of Class C IP address has its first 3 bits set to 110, that is: Class C IP addresses
range from 192.0.0.x to 223.255.255.x. The default subnet mask for Class C is 255.255.255.x.
Class C gives 2097152 (221) Network addresses and 254 (28-2) Host addresses.
Class C IP address format is:
110NNNNN.NNNNNNNN.NNNNNNNN.HHHHHHHH
Class D Address
Very first four bits of the first octet in Class D IP addresses are set to 1110, giving a range of:
Class D has IP address rage from 224.0.0.0 to 239.255.255.255. Class D is reserved for
Multicasting. In multicasting data is not destined for a particular host, that is why there is no
need to extract host address from the IP address, and Class D does not have any subnet mask.
Class E Address
This IP Class is reserved for experimental purposes only for R&D or Study. IP addresses in this
class ranges from 240.0.0.0 to 255.255.255.254. Like Class D, this class too is not equipped with
any subnet mask.
Each IP class is equipped with its own default subnet mask which bounds that IP class to have
prefixed number of Networks and prefixed number of Hosts per network. Classful IP addressing
does not provide any flexibility of having less number of Hosts per Network or more Networks
per IP Class.
CIDR or Classless Inter Domain Routing provides the flexibility of borrowing bits of Host part
of the IP address and using them as Network in Network, called Subnet. By usingsubnetting, one
single Class A IP address can be used to have smaller sub-networks which provides better
network management capabilities.
Class A Subnets
In Class A, only the first octet is used as Network identifier and rest of three octets are used to be
assigned to Hosts (i.e. 16777214 Hosts per Network). To make more subnet in Class A, bits from
Host part are borrowed and the subnet mask is changed accordingly.
For example, if one MSB (Most Significant Bit) is borrowed from host bits of second octet and
added to Network address, it creates two Subnets (21=2) with (223-2) 8388606 Hosts per
Subnet.
The Subnet mask is changed accordingly to reflect subnetting. Given below is a list of all
possible combination of Class A subnets:
In case of subnetting too, the very first and last IP address of every subnet is used for Subnet
Number and Subnet Broadcast IP address respectively. Because these two IP addresses cannot be
assigned to hosts, sub-netting cannot be implemented by using more than 30 bits as Network
Bits, which provides less than two hosts per subnet.
Class B Subnets
By default, using Classful Networking, 14 bits are used as Network bits providing (214) 16384
Networks and (216-2) 65534 Hosts. Class B IP Addresses can be subnetted the same way as
Class A addresses, by borrowing bits from Host bits.
Class C Subnets
Class C IP addresses are normally assigned to a very small size network because it can
only have 254 hosts in a network.
Conclusion: Thus, we have studied working of subletting and find the subnet masks.
Output:
FAQ:
1) IPv4 has 32-bit address length 1) IPv6 has 128-bit address length
2) It Supports Manual and DHCP address 2) It Supports Auto and renumbering address
configuration. configuration.
3) In IPv4 end to end connection integrity is 3) In IPv56 end to end connection integrity is
Unachievable Achievable.
4) It can generate 4.29x10^9 address space. 4) Address space of IPv6 is quite large it can
produce 3.4x10^38 address space.
→ 1) ARP:- Address Resolution Protocol (ARP) is a communication protocol used to find the MAC
(Media Access Control) address of a device from its IP address. This protocol is used when a device
wants to communicate with another device on a Local Area Network or Ethernet.
2) RARP:-
• It is a networking protocol used by the client system in a local area network (LAN) to request
its IPv4 address from the ARP gateway router table. A table is created by the network
administrator in the gateway-router that is used to find out the MAC address to the
corresponding IP address.
• When a new system is set up or any machine that has no memory to store the IP address,
then the user has to find the IP address of the device. The device sends a RARP broadcast
packet, including its own MAC address in the address field of both the sender and the
receiver hardware. A host installed inside of the local network called the RARP-server is
prepared to respond to such type of broadcast packet. The RARP server is then trying to
locate a mapping table entry in the IP to MAC address. If any entry matches the item in the
table, then the RARP server sends the response packet along with the IP address to the
requesting computer.
3. What is classful addressing?
➔ Classful addressing:-
• Classful addressing is an IPv4 addressing architecture that divides addresses into five groups.
i.e, A, B, C, D and E.
• Prior to classful addressing, the first eight bits of an IP address defined the network a given
host was a part of. This would have had the effect of limiting the internet to just 254
networks. Each of those networks contained 16,777,216 different IP addresses. As the
internet grew, the inefficiency of allocating IP addresses this way became a problem. After
all, there are a lot more than 254 organizations that need IP addresses, and a lot fewer
networks that need 16.7 million IP addresses to themselves
→ Classless addressing:-
• Classless addressing is an IPv4 addressing architecture that uses variable-length subnet masking.
• The solution would come in 1993, as Classless Inter-Domain Routing (CIDR) introducing the
concept of classless addressing. You see, with classful addressing, the size of networks is fixed.
Each address range has a default subnet mask. Classless addressing, however, decouples IP
address ranges from a default subnet mask, allowing for variable-length subnet masking (VLSM).
• Using classless addressing and VLSM, addresses can be allocated much more efficiently. This is
because network admins get to pick network masks, and in turn, blocks of IP addresses that are
the right size for any purpose.
subnetting supernetting
3) In subnetting, the mask bits are moved 3) While in supernetting, The mask bits are
towards right. moved towards left.