gpt4 book ai didi

CIDR 和 IP 地址数

转载 作者:行者123 更新时间:2023-12-05 03:58:53 25 4
gpt4 key购买 nike

我读到 10.240.0.0/24 最多可以托管 254 个 IP 地址。怎么样?
我如何直观地理解 /24 在这里做什么来帮助提供 254 个唯一的 ip 地址?

最佳答案

TL;博士;

计算主机数量的一种简短方法是

2 ^ ( 32 - 24 ) - 2 = 256

因为:

  1. 我们在做位运算(01,两个可能的值)
  2. 一个 IP 是一组 4 个八位位组,一个八位位组是 8 位 (4 * 8 = 32)
  3. 24 是您的 CIDR
  4. 每个子网上都有两个保留IP,广播地址和子网0,它们不应该用于主机

CIDR 是在按位运算的帮助下计算的。

IP 是一组 4 个八位字节,每个字节用点分隔。

255.255.255.255
=
11111111.11111111.11111111.11111111

当您指定 /24 的 CIDR 时,您是在为您的 IP 请求一个带有掩码的子网,该掩码将填充 24 位设置为 1

11111111.11111111.11111111.00000000
=
255.255.255.0

你的IP是

10.240.0.0
=
00001010.11110000.00000000.00000000

现在我们可以在您的 IP 和您的子网之间应用按位与

11111111.11111111.11111111.00000000
&
00001010.11110000.00000000.00000000
=
00001010.11110000.00000000.00000000

所以您最终将 10.240.0.0 作为您的 IP 前缀。
相同的子网可以应用于后续 IP

10.240.0.1

11111111.11111111.11111111.00000000
&
00001010.11110000.00000000.00000001
=
00001010.11110000.00000000.00000000

提供相同的 10.240.0.0 IP 前缀

10.240.0.2

11111111.11111111.11111111.00000000
&
00001010.11110000.00000000.00000010
=
00001010.11110000.00000000.00000000

提供相同的 10.240.0.0 IP 前缀
等等等等

总而言之,按位运算非常简单:

  • 每次你有一个 0 & x 它将等于 0
  • 每次你有一个 1 & x 它将等于 x

所以这意味着对于 10.240.0.0/24,您有一个 255.255.255.0 的子网,因此 IP 范围从 10.240.0.010.240.0.255

这仍然为您提供 256 个可能的地址吗?

嗯,是的,但你必须记住,在 IPv4 中,你有两个不可用的地址:

  • 子网零(您的范围的第一个地址)
  • 和广播地址(您范围内的最后一个地址)

Special Addresses:

From the Assigned Numbers memo [Reynolds, J., and J. Postel, "Assigned Numbers", RFC-943, USC/Information Sciences Institute, April 1985.]:

"In certain contexts, it is useful to have fixed addresseswith functional significance rather than as identifiers ofspecific hosts. When such usage is called for, the addresszero is to be interpreted as meaning "this", as in "thisnetwork". The address of all ones are to be interpreted asmeaning "all", as in "all hosts". For example, the address128.9.255.255 could be interpreted as meaning all hosts onthe network 128.9. Or, the address 0.0.0.37 could beinterpreted as meaning host 37 on this network."

It is useful to preserve and extend the interpretation of thesespecial addresses in subnetted networks. This means the valuesof all zeros and all ones in the subnet field should not beassigned to actual (physical) subnets.

来源: https://www.ietf.org/rfc/rfc950.txt

现在,如果您执行 256 - 2,您就有了 254 可用主机。

总结:

  • CIDR:10.240.0.0/24
  • 子网掩码:255.255.255.0(当 IP 显示为八位组时,1 的 24 倍)
  • IP 范围:10.240.0.0 - 10.240.0.255
  • 子网零:10.240.0.0
  • 广播地址:10.240.0.255
  • 主机 IP 范围:10.240.0.1 - 10.240.0.254

关于CIDR 和 IP 地址数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57618233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com