Monday, December 17, 2007

VLSM Part Three: VLSM, Finally!

Now that we've gone through the nitty gritty details of IP addressing, at last we come to VLSM itself.

VLSM, or Variable Length Subnet Masking, is a method that is very widely used in order to make efficient use of the IP addresses available to us. For example if we have a Class C IP block and a PPP (Peer to Peer) link that will only ever have 2 active hosts, why should we waste all 254 usable addresses on it? That would be a waste! Instead, we manipulate the subnet mask in order to fit the number of hosts that we actually need.

To do this, you need to first know two important formulas:

2^n = The number of available subnets where n is the number of bits used for the network portion of the address.
Ex. With a Class C IP block, a subnet mask of 255.255.255.240 would give us 2^4 = 16 subnets

2^h-2 = The number of usable hosts on a subnet where h is the number of bits used for the host portion. You subtract 2 from the total because the network and broadcast addresses are not usable.
Ex. With a Class C IP block, a subnet mask of 255.255.255.240 would give (2^4)-2 = 14 usable hosts per subnet.

As a sidenote, in IPv6 broadcast addresses have been completely replaced by multicast addresses. What does this mean for us? The formula for usable hosts should now be 2^h-1 for IPv6 since the broadcast address is now usable.

So anyway, back to an example. Now that we know the two all important formulas for VLSM, let's do some theory stuff. Lets say we have a Class C address of 205.4.6.0/24, and we need to be able to use this on our PPP WAN link and addressing the LAN that will have oh, 63 users. For now and for simplicity's sake, we'll start off with the largest subnet which is the LAN with 63 users.

We need at least 61 usable addresses, so let's start plugging in some numbers to our formula, 2^h-2. 5? Nope, that would give us 30. How about 6? That would give us 62 usable addresses which is enough. But what happens if in the future, our LAN grows by 2 devices? We would need to redesign everything, so let's build in some room for growth and use 7 bits of information for the host portion of the address. That means we will use 32 - 7 = 25 bits of the subnet mask for the network portion of the address, which gives us a mask of 255.255.255.128 and 126 usable hosts.

So as we stand this is what we have:
LAN (61 hosts needed):
Network: 205.4.6.0/25
Range: 205.4.6.0 - 205.4.6.127
Usable Hosts: 205.4.6.1 - 205.4.6.126

The next IP address usable for subnetting purposes is 205.4.6.128 since we have already used 0-127 in our first network, so let's start there. On our PPP WAN link, we only need two usable hosts. Let's try using 2 bits for the host portion of the network: 2^h-2 =...........2! Perfect! Since it is a PPP link we don't have to worry about future growth, so having the exact number of hosts needed is perfectly fine. That means for this network, we will be using 32 - 2 = 30 bits of the subnet mask for the network portion of the address, which gives us a mask of 255.255.255.252 with 2 usable hosts.

So finally, we end up with this:
LAN (61 hosts needed):
Network: 205.4.6.0/25
Range: 205.4.6.0 - 205.4.6.127
Usable Hosts: 205.4.6.1 - 205.4.6.126

WAN (2 hosts needed):
Network: 205.4.6.128/30
Range 205.4.6.128 - 205.4.6.131
Usable Hosts: 205.4.6.129 - 205.4.6.130

And we're done! We even still have the rest of the Class C range from 205.4.6.131 - 205.4.6.255 to dedicate to future growth if needed.

No comments: