How to tell if two IP ranges are adjacent
Task:
You have two CIDR notations representing two IP ranges, and you want to tell if they are adjacent, or not.
Steps to answer:
- The prefix value must be the same. CIDR notations with different prefix can never be adjacent
- Used the steps outlined in How to quickly tell the first and last IP in a CIDR range, to figure out the first and last ip numbers in the two ranges
- Check if adding 1 to the last IP address of one will lead to the starting IP address of the other. If so, then the two ranges are adjacent
Example:
Determine if 10.0.4.0/24 and 10.0.5.0/24 are adjacent
- Using the steps in How to quickly tell the first and last ip in a CIDR range, the start and end IP number for 10.0.4.0/24 is 10.0.4.0 and 10.0.4.255
- Using the steps in How to quickly tell the first and last ip in a CIDR range, the start and end ip number for 10.0.5.0/24 is 10.0.5.0 and 10.0.5.255
- Adding 1 to 10.0.4.255 indeed leads to 10.0.5.0 which is the start of the second range, hence they are adjacent
Previous post: How To Calculate How Many Smaller IP Ranges Can Be Gotten From a Bigger IP Range
Next post: How to quickly calculate exponents of base 2
No comments:
Post a Comment