简体   繁体   English

亚马逊VPC n ^ 2 -4 IP地址? CIDR块

[英]Amazon VPC n^2 -4 IP Addresses? CIDR Block

I was in the process of creating a new AWS VPC for my instances. 我正在为我的实例创建一个新的AWS VPC。 However, I noticed that when I used CIDR Notation to create the VPC & Public Subnet, AWS indicates that I have n^2 - 4 (where n is the # of bits) available IP addresses? 但是,我注意到当我使用CIDR Notation创建VPC和公共子网时,AWS表明我有n ^ 2 - 4(其中n是位数)可用的IP地址? Why is this? 为什么是这样?

I understand that when n^2 -2 occurs it is usually to remove the case where bits are all 0s or all 1s. 据我所知,当n ^ 2 -2出现时,通常会删除位为全0或全1的情况。 But am not sure why it is - 4 in this case. 但我不确定为什么 - 在这种情况下是4。

AWS VPC屏幕

Here the /28 indicates 11 IP addresses available when I expected 15 or 13, and 251 when I expected 255 or 253 / 28表示当我预期15或13时可用的11个IP地址,而当我预期为255或253时表示251

Important 重要

AWS reserves both the first four IP addresses and the last IP address in each subnet CIDR block; AWS保留每个子网CIDR块中的前四个IP地址和最后一个IP地址; they're not available for you to use. 它们无法供您使用。 For example, in a subnet with CIDR block 10.0.0.0/24, the following IP addresses are reserved: 10.0.0.0, 10.0.0.1, 10.0.0.2, 10.0.0.3, and 10.0.0.255. 例如,在具有CIDR块10.0.0.0/24的子网中,保留以下IP地址:10.0.0.0,10.0.0.1,10.0.0.2,10.0.0.3和10.0.0.255。

http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html - http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html

In addition to the network and broadcast addresses, there's a default gateway automatically provisioned, as well as IP addresses used for delivering services automatically provided by the VPC infrastricture in each subnet (like DNS resolvers and DHCP). 除了网络和广播地址之外,还有一个自动配置的默认网关,以及用于提供由每个子网中的VPC基础设施自动提供的服务的IP地址(如DNS解析器和DHCP)。 These are largely transparent to you, but that is where the addresses are going and the reason why they aren't available for assignment to instances in the subnet. 这些对您来说基本上是透明的,但这就是地址的去向以及它们无法分配给子网中的实例的原因。

The first four IP addresses and the last IP address in each subnet CIDR block are not available for you to use, and cannot be assigned to an instance. 每个子网CIDR块中的前四个IP地址和最后一个IP地址不可供您使用,也不能分配给实例。 For example, in a subnet with CIDR block 10.0.0.0/24,the following five IP addresses are reserved: 例如,在具有CIDR块10.0.0.0/24的子网中,保留以下五个IP地址:

• 10.0.0.0: Network address.

• 10.0.0.1: Reserved by AWS for the VPC router.

• 10.0.0.2: Reserved by AWS for mapping to the Amazon-provided DNS.

• 10.0.0.3: Reserved by AWS for future use.

• 10.0.0.255: Network broadcast address.

Since AWS does not support broadcast in a VPC, therefore they reserve this address. 由于AWS不支持VPC中的广播,因此他们保留此地址。

Now that you know what are the reserved IP address you may be wondering How to calculate the total number of usable IP addresses of a given VPC CIDR Block? 既然您知道什么是保留的IP地址,您可能想知道如何计算给定VPC CIDR块的可用IP地址总数

Use the formula to calculate a normal CIDR Block then subtract 5 because AWS uses the first 4 and the last address. 使用公式计算正常CIDR块然后减去5,因为AWS使用前4个和最后一个地址。

  1. Subtract 32 with the mask number. 用掩码编号减去32。
  2. Raise the number 2 to the power of the answer in Step #1. 在步骤#1中将数字2提升到答案的幂。
  3. Subtract 5 because AWS uses 5 of them. 减去5因为AWS使用其中的5个。

Example: Given the netmask /27 示例:给出netmask / 27

Step 1) 32 - 27 = 5
Step 2)  2^5 = 32
Step 3)  32 - 5 = 27  Because VPC uses 5 addresses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM