关于将两个特定IP地址合并为合适CIDR网段的技术咨询
Hey there, let's break this down step by step so it makes sense.
First off, let's clear up that /2 idea right away: that's a terrible fit. A /2 CIDR covers the entire range from 128.0.0.0 to 191.255.255.255—way, way broader than even a /24, so it's absolutely not what you want.
Now, to find the smallest CIDR that includes both 172.22.254.67 and 172.22.254.68, we need to look at their binary structure:
- The last byte of
172.22.254.67is01000011 - The last byte of
172.22.254.68is01000100
The first three octets (172.22.254) are identical, so we only care about the common prefix in the last byte. Comparing those two binary strings, the first 5 bits are the same (01000), and they diverge after that. Adding those 5 bits to the 24 bits from the first three octets gives us a 29-bit common prefix.
The correct CIDR for this is 172.22.254.64/29. Let's break down what this means:
- The subnet mask here is
255.255.255.248 - It covers the IP range from
172.22.254.64to172.22.254.71(8 total IPs)
This is the smallest possible CIDR that includes both your target IPs. Unfortunately, there's no CIDR that only covers exactly these two IPs—since they sit on the edge of two smaller /30 subnets (one covering 64-67, the other 68-71), we have to go up one size to /29 to include both.
This solves your character limit issue (you only need one string) while keeping the allowed IP range much tighter than a /24.
备注:内容来源于stack exchange,提问作者oldenuf

