Friday, August 15, 2014

What IP addresses are included in a subnet "range"?




I'd like some help understanding subnets (CIDR).



I'm using a tool to check if an IP is in an acceptable range given a CIDR address. When I input an IP address (12.245.105.190) and check it against the same address with a subnet mask (12.245.105.190/30), any value less than 31 shows "NOT IN SUBNET" but gives a range that would seem to include the IP address:



** NOT IN SUBNET **
IPV4 ADDRESS 12.245.105.190
IPV4 NETWORK 12.245.105.190
IPV4 CIDR PREFIX 30
IPV4 RANGE START 12.245.105.188 <-- seems smaller than my IP

IPV4 RANGE END 12.245.105.193 <-- seems larger


Can you help me understand what I'm missing?


Answer



The subnet mask is a bit mask. The appended /30 means the netmask spans the highest 30 bits (out of 32 bits):



       12 .       245 .       105 .       190 IPv4 address decimal
0000 1100 . 1111 0101 . 0110 1001 . 1011 1110 IPv4 address binary
1111 1111 1111 1111 1111 1111 1111 1100 netmask

0000 1100 . 1111 0101 . 0110 1001 . 1011 1100 network prefix


The 30 bits to the left are the network part/prefix.
The final two bits at the right side comprise the host part. This means the host portion (the two lowest bits) can be




  • 0 0

  • 0 1

  • 1 0


  • 1 1



Which are, when put together with the network prefix (first 30 bits from above)



0000 1100 . 1111 0101 . 0110 1001 . 1011 1100  
12 . 245 . 105 . 188
0000 1100 . 1111 0101 . 0110 1001 . 1011 1101
12 . 245 . 105 . 189
0000 1100 . 1111 0101 . 0110 1001 . 1011 1110

12 . 245 . 105 . 190
0000 1100 . 1111 0101 . 0110 1001 . 1011 1111
12 . 245 . 105 . 191


So there are four addresses on this subnetwork, where the first 00 and last 11 are reserved for the network and broadcast respectively. This means .188, .189, .190, and .191 are part of the subnetwork, contrary to .188 - .193 claimed by the - seemingly broken - online tool.






See also Wikipedia - Subnetwork - Internet Protocol version 4 for more details on IPv4 subnetworks generally, and network prefixes particularly.



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...