Sunday, October 11, 2009

Subnet, Subnet mask and find out the machines in the same sub network

Awrite. Here's the next deal.

What's this subnet that people talk about?

A subnet or subnetwork is like virtualizing a network. Though we have one network, we use masks to make it behave like more than one. Like physical processors and logical processors.

So, here was a guy who asked me how in the world I could claim that the two IP addresses 9.134.60.30 and 9.134.60.200 do not belong to the same subnet.
He thought I'd gone crazy. Two months ago, I'd have said the same.

How do we determine if the given IPs belong to the same subnet? This is where the subnet mask comes into the picture.

Let's take 255.255.255.192 as the subnet mask for the second IP.

Let me take it further in steps.

Step 1: Take one IP and the subnet mask.
Step 2: Do a bitwise AND of the two addresses.

For those of you with the thought, "Oh right, but er.. how?", each of the four numbers in the IP should be converted to an eight digit binary.
eg. 9 would be 00001001. (Use the windows calculator to convert big numbers if you don't want to sit and think about it). Some of you may have a hex address (in system logs etc). eg. "9a ff cc aa". It is simpler in this case. each of them would transform to a four digit binary and you don't need any calculators here. '9 a' would be '1001 1010'.

For our example,

IP address : 00001001 10000110 00111100 11001000
subnet mask: 11111111 11111111 11111111 11000000

Bitwise AND: 00001001 10000110 00111100 11000000
(1 only if both
inputs are 1)

Step 3: Ta da. The result of the bit wise AND is your network address.
Here, it is 9.134.60.192

Step 4:
How many IPs can be in this subnet?
Count the number of zeroes from the right end. Six.
Maximum possible number of machines would be: 2 to the power of 6, which is 64.
Every subnet has a network address (one we found there) and a gateway IP. leaving those two, sixty two other IPs can be accommodated.
Including those two IPs, the range is usually 9.134.60.192 to 9.134.60.255

...and there you go, 9.134.60.30 is nowhere close to being in this subnet.

Peace.

No comments:

Post a Comment