Tuesday, January 21, 2014

Discontinuous subnet masks

The subnet mask for a particular network is 255.255.31.0. Which of the following pairs of IP addressed could belong to this network? (GATE 2003)

A: 172.57.88.62 & 172.56.87.233
B: 10.35.28.2 & 10.35.29.4
C: 191.203.31.87 & 192.234.31.88
D: 128.8.129.43 & 128.8.161.55

Now here a lot of people get suspicious about the validity of this given subnet mask (31 = 00011111 ).
As according to the definition of subnet mask (from many renowned books, personally read 3 of them), this is a 32-bit number(for ipv4) where all the bits of the network part are represented as “1”and all the bits of the host part are represented as “0”. That means all 0’s should be following 1’s in a subnet mask.

Then that means this given subnet mask is wrong?
The answer is No. This subnet mask is completely fine. This is an example of a discontinuous subnet mask, which is no longer supported on most routers. Discontinuous subnet masks are still supported on some network access control devices for features like ACLs. (Sometimes, notably on Cisco routers, the subnet masks are written inverted, in this case, so you'll see 0.0.0.255, for example, to mean a /24). But practically these are not being used a lot nowadays. So Many people are unaware of this.

Those authors are also not wrong in their definition of a subnet mask. They are only referring to the latest trend being followed in Networking.

Now back to the question. The principle is the same: convert the dotted-quad IP addresses and mask to 32-bit unsigned integers and AND each address with the mask. If the results are the same, they're in the same subnet. 

NM = 255.255.31.0
• Hence, first, two parts of the n/w have to be same. Last part(third & fourth) can be anything.  This removes the possibility for A and C options.
• Now for B, consider the third part:
28 = 0001 1100
31 = 0001 1111
----------------------------
        0001 1100
 
29 = 0001 1101
31 = 0001 1111
----------------------------
        0001 1101
Last 5 bits are different. So they are not on the same network. 


• Now for D, consider the third part:
129 = 1000 0001
31  =  0001 1111
---------------------------
          1000 0001 


161 = 1010 0001
31   = 0001 1111
--------------------------
          1000 0001
Last 5 bits(network part) are same. Hence, the correct answer is D.

No comments: