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

前提是你 提交于 2019-12-22 09:05:16

问题


I was in the process of creating a new AWS VPC for my instances. 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? 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. But am not sure why it is - 4 in this case.

Here the /28 indicates 11 IP addresses available when I expected 15 or 13, and 251 when I expected 255 or 253


回答1:


Important

AWS reserves both the first four IP addresses and the last IP address in each subnet CIDR block; 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.

— 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). 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.




回答2:


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. For example, in a subnet with CIDR block 10.0.0.0/24,the following five IP addresses are reserved:

• 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.




回答3:


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?

Use the formula to calculate a normal CIDR Block then subtract 5 because AWS uses the first 4 and the last address.

  1. Subtract 32 with the mask number.
  2. Raise the number 2 to the power of the answer in Step #1.
  3. Subtract 5 because AWS uses 5 of them.

Example: Given the netmask /27

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


来源:https://stackoverflow.com/questions/31214333/amazon-vpc-n2-4-ip-addresses-cidr-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!