Sunday, August 28, 2022

IPv4 Subnetting

 What is Subnet?

  • A subnet, or subnetwork, is a network inside a network. Subnets make networks more efficient. Through subnetting, network traffic can travel a shorter distance without passing through unnecessary routers to reach its destination.
  • Imagine Alice puts a letter in the mail that is addressed to Bob, who lives in the town right next to hers. For the letter to reach Bob as quickly as possible, it should be delivered right from Alice's post office to the post office in Bob's town, and then to Bob. If the letter is first sent to a post office hundreds of miles away, Alice's letter could take a lot longer to reach Bob.
  • Like the postal service, networks are more efficient when messages travel as directly as possible. When a network receives data packets from another network, it will sort and route those packets by subnet so that the packets do not take an inefficient route to their destination.

Why Subnetting?

Assigning multiple Classful networks to each company would result in network depletion.
So, a single Classful network was assigned to each company with the expectation of subnetting.
If any company has many branch offices which are geographically separated, if connected are said to be connected on MAN or WAN. In MAN/WAN, we mostly used serial technology and router. As router route between the network, it every port should be in different network. Now, from ISP/IANA we have got only one single network, and we can’t assign single network to all router interfaces. So, in 1985 subnetting was introduced. Hence, subnetting is done.

  • Each IP network that is purchased is only good for a single broadcast domain (VLAN).
  • Often unused/unallocated host space within a given network.
  • Subnetting = Dividing a single, allocated network into multiple sub-networks.
  • Minor loss of available hosts addresses.

Subnetting is nothing, but a mask manipulation.

Design Rule: Two directly connected communicating devices should be in same subnet, and two port of router should be in different network/subnet.

Subnetting creates additional network IDs at the expense of host IDs and can be used with either A, B or C class addresses. These additional network addresses are called subnets and not networks because to the Internet, the original address is still a class B network address but locally the class B network address can be broken down to manageable subnets that function as actual network addresses. Why use subnets? Subnets are interconnected using routers, and routers improve network performance by reducing traffic and minimizing disruption due to broadcast messages. Large networks become more manageable when subnets are deployed.

  • With a network that has been assigned from an ISP you have two portions:
The “network” part
The “host” part

ISP doesn’t care what you do with Host bits, but you are not allowed to modify the “network” bits.

Suppose ISP provided 192.1.1.X classful IP network.
From the IP address, we understand, the first 3 bit of first octet if converted in binary, will have “110”, which mean ISP provided the IP network from class c network, which mean we have,

  • 24 bits in network portion
  • 8 bits in host portion
But, in our company we have requirement of 8 different network, and we got one single class C classful address from ISP.
So, now we must do subnetting of these IP network.
So, subnetting can be done with network point of view or host point of view.
From network point of View:
  • As we have requirement of 8 network, which mean we need 3 bits from the host portion of the classful address.
  • So, now the network portion will be 24 +3 = 27 bits.
  • Total bits in IP Address are 32 bits, and now network bits are 27.
  • So, host side will have 32 -27 = 5 bits, which mean 32 host per network.
From Host point of View:
  • As we require 8 networks, and in each network if we require 30 hosts per network.
  • For 30 hosts, we need 5 bits.
  • As per IANA rule, whenever we do subnetting, subnet can be of 2, 4, 8, 16, 32, 64, 128, 255 host.
  • So, in one subnet we have 32 host, which is of 5 host bits.
  • Total bits in IP Address are 32 bits, and now host bits are 5.
  • So, network side will have 32-5 = 27 bits.
  • From ISP we got IP network of 24 bits, and now we got network of 27 bits.
  • Which means we have 3 bits borrowed from host side, which can give us 8 different networks.
Finally, from above both point of view we will have below 8 sub-networks each of 32 hosts as:

Subnet Mask

  • To create subnets, you need a subnet mask that defines which bits will be used to create the new network address out of the 32-bit IP addresses. By "ANDing" the 32-bit IP address with a 32-bit mask, we create a 32-IP address that represents <netid, subnetid> becoming our new network address. 
  • What do these masks look like? If we start with a basic class A address and do not define any subnets, the mask will look like 255.0.0.0 which is called a natural or default mask
  • Only those bits that are set as a 1 will be considered when defining a network address. 
  • In this case, all the bits in the first byte of the IP address will be considered. 
  • The natural mask for a class B address is 255.255.0.0 and for a class C address it is 255.255.255.0. 
  • To create more network addresses (subnets) we need to move the mask bits to the right (changing 0 bits into 1s) to convert host bits into network bits.
Remember that while we (as humans) represent IP addresses as dotted decimal, computers see it simply as a long string of 32-bits.
A subnet mask is another string of 32-bits that is used as a comparison tool against the IP address.
The subnet mask can divide the IP address anywhere…it doesn’t have to fall on an even byte boundary

From any ISP if we lease one classful network, we need to do subnetting, we first need to get out network requirement, and then we need to find how much bit we can then borrow or steal from host portion, as we can’t make any changes from network portion.

We can use below formula:

2^sn >= Quantity of subnets you’ve created.
(where “sn” = subnetting bits)
  • Suppose we lease 172.17.0.0/16.
  • If Quantity of subnets we want 8, so the sn value will be 3.
  • So, we will borrow 3 bits from host portion.
  • From lease network, we have 16 bits in host portion, so we will borrow 3 bits.
  • Now, network portion will be 16 + 3 = 19 bits.
  • So, the new subnet mask will be 19 of our all 8 sub-networks.

Bits to Mask

Now from above we got subnet mask in bits.
How will we convert these bits into Network mask?
We can use below logic to convert bits to mask.

Now, if we have subnet mask as /27, so the nearest default mask is 24.
Now, 24 + 3 = 27.
So, from 4 octet we have 3 bits in network portion.
From above logic, from left side if you see, you will get the mask value for 4th octet.
So, the Netmask for /27 will be 255.255.255.224.

Classful Address is an address with default mask
For example: 16.20.20.1 255.0.0.0

Classless Address is an address with any other mask, but not with a default mask.
For example: 16.20.20.1 255.255.255.224

By default, Cisco router will only allow classful address to be configured on interfaces.
To use classless address, need to configure “IP classless” command.
From Cisco IOS version 12.0 onwards, “IP classless” and IP subnet-zero” has become a default command. Hence, no need of configuring.

 Simple Logic for Same Length Subnetting

An ISP leases you the following network:  199.10.1.0 / 24
You need to create 22-subnetworks from this single network.
You need to get answer for below Question

  • What will be your new subnet mask (dotted decimal)? 255.255.255.248
For New subnet Mask, we can use above formula as:
2^sn >= Quantity of subnets required
2^sn >= 22
2^5 will give 32 subnets, which is greater than 22.
So, we got subnet bits as 5 bits which need to be borrowed/steal from host portion.
Current mask is 24 + subnet bits is 5 = New subnet mask will be /29
 To convert this subnet mask to Netmask, use above logic “Bits to Mask”.
5 bits from left hand side, will give 248.
So, the Netmask will be 255.255.255.248

  • How many hosts will be supported in each subnet? 8 hosts
Now we have subnet bits as 5, so remaining will be host bits as 3 bits.
So, for 3 bits we will have 8 hosts

  • What is the subnet address of the fourth subnet? 199.10.1.24
From the logic diagram, we can see for /29 on the left, we have 8, which mean every subnet will be multiple of 8.
1st subnet = 199.10.1.0/29
2ndsubnet = 199.10.1.8/29
3rd subnet = 199.10.1.16/29
4th subnet = 199.10.1.24/29

  • What is the broadcast address of the sixth subnet? 199.10.1.47
1st subnet = 199.10.1.0/29
2ndsubnet = 199.10.1.8/29
3rd subnet = 199.10.1.16/29
4th subnet = 199.10.1.24/29
5th subnet = 199.10.1.32/29
6th subnet = 199.10.1.40/29
7th subnet = 199.10.1.48/29
For 6th subnet broadcast address will be one less than 07th subnet address.

 Problem with Same Length Subnetting and its Solution

  • When same length subnetting was first introduced, it was simply known as "subnetting." Its biggest benefit is that it validates the idea of borrowing bits from an IP address host field to create locally significant subnet identification addresses.
  • The use of same length subnetting saves a router the task of having to handle an entire IP address, because the router deals only with the digits selected by the mask. Further, it divides the address space into an adequate number of subnets and can therefore meet the needs of large LANs.
  • In IP classes of IPv4 addresses, there are fixed subnets with a fixed number of hosts and networks. For example, a class C IP address has a 24-bit network part and an 8-bit host part. Similarly, Class A addresses have an 8-bit network part and a 24-bit host part.
  • What this means is that in this method of subnet masking, subnets are rarely filled to capacity. This results in the inefficient use of IP address space, and a significant waste of unused addresses.
  • To overcome these challenges, a VLSM is better. In networks with many unassigned IP addresses, VLSM uses IP address space more efficiently, and thus prevents waste.

Variable Length Subnet Mask (VLSM)

VLSM stands for Variable Length Subnet Mask where the subnet design uses more than one mask in the same network which means more than one mask is used for different subnets of a single class A, B, C, or a network. It is used to increase the usability of subnets as they can be of variable size. It is also defined as the process of subnetting of a subnet.

Procedure of implementing VLSM –

In VLSM, subnets use block size based on requirement so subnetting is required multiple times. Suppose there is an administrator that has four departments to manage. These are sales and purchase department with 120 computers, development department with 50 computers, accounts department with 26 computers and management department with 5 computers.

  • If the administrator has IP 192.168.1.0/24, department wise IPs can be allocated by following these steps:
  • For each segment select the block size that is greater than or equal to the actual requirement which is the sum of host addresses, broadcast addresses and network addresses. Make a list of subnets possible:

Slash Notation

Hosts/subnet

/24

256

/25

128

/26

64

/27

32

/28

16

/29

8

/30

4

/31

2

  • Arrange all the segments in descending order based on the block size that is from highest to lowest requirement.
Sales and Purchase: 120
Development: 50
Accounts: 26
Management: 5

  • The highest IP available must be allocated to highest requirement so the sales and purchase department gets 192.168.1.0/25 which has 128 valid addresses that can easily be available for 120 hosts. The subnet mask used is 255.255.255.128
  • The next segment requires an IP to handle 50 hosts. The IP subnet with network number 192.168.1.128/26 is the next highest which can be assigned to 64 hosts thus fulfilling the requirement of development department. The subnet mask used is 255.255.255.192
  • Similarly, the next IP subnet 192.168.1.192/27 can fulfil the requirements of the accounts department as it has 32 valid hosts IP which can be assigned to 26 computers. The mask used is 255.255.255.224
  • The last segment requires 5 valid hosts IP which can be fulfilled by the subnet 192.168.1.224/29 which has the mask as 255.255.255.248 is chosen as per the requirement. The IP with the mask 255.255.255.240 could be chosen but it has 14 valid host IPs, and the requirement is less in comparison so the one that is comparable with the requirement is chosen.
  • So, below is the final IP assignment overall for required departments
Sales and Purchase: 120 -- 192.168.1.0/25
Development: 50 -- 192.168.1.128/26
Accounts: 26 -- 192.168.1.192/27
Management: 5 -- 192.168.1.224/29

  • So, we still have many unused IP which can be used for future purpose.
  • Thus, there is less IP wastage in VLSM as compared to same length subnetting.

IPv4 Address/Route Summarization

Aggregating multiple subnets into a single network advertisement.
That advertisement does not break classful boundaries.
Route summarization is a method where we create one summary route that represent multiple networks/subnets. It’s also called route aggregation.
Some routers perform summarization by default.
Summarization has several advantages:

  • Saves memory: routing tables will be smaller which reduces memory requirements.
  • Saves bandwidth: there are less routes to advertise so we save some bandwidth.
  • Saves CPU cycles: less packets to process and smaller routing tables to work on.
  • Stability: Prevents routing table instability due to flapping networks.
There are also some disadvantages to summarization:
  • Forwarding traffic for unused networks: a router will drop traffic when it doesn’t have a matching destination in its routing table. When we use summarization, it’s possible that the summary route covers networks that are not in use. The router that has a summary route will forward them to the router that has advertised the summary route.
  • Sub-optimal routing: routers prefer the path with the longest prefix match. When you use summaries, it’s possible that your router prefers another path where it has learned a more specific network from. The summary route also has a single metric.
Example
Network: 10.10.32.0 / 20
Network: 10.10.48.0 / 20
Subnet mask: 255.255.240.0
Conversion of network-id into bits
10.10.0010hhhh.hhhhhhhh / 20
10.10.0011hhhh.hhhhhhhh / 20
AND operation result: 10.10.001hhhhh.hhhhhhhh
10.10.32.0 / 19 (summarized network)

 

IPv4 Supernetting

  • Aggregating multiple networks (could be subnets or classful networks) into a single network advertisement.
  • That advertisement breaks classful boundaries
  • Supernetting can only be done manually.
Example
Network: 192.168.1.0/ 24
Network: 192.168.2.0/ 24
Conversion of network-id into bits
192.168.00000001.hhhhhhhh
192.168.00000010.hhhhhhhh
AND operation result: 192.168.000000hh.hhhhhhhh
192.168.0.0 / 22 (Supernet)

When performing summarization or supernetting ask yourself, “what bits…from left-to-right…do all of these networks have in common?”
Answer to the above question will determine new mask.

No comments:

Post a Comment