CIDR Address is not within CIDR Address from VPC - amazon-web-services

I have tried every combination of IP ranges for my CIDR block on my new VPC for AWS.
My current CIDR is 172.31.0.0/16
171.31.0.0/32 (CIDR Address is not within CIDR Address from VPC)

An IPv4 address consists of 32 bits.
1) /32 in CIDR x.x.x.x/32 means use all 32 bits to form a range of addresses. In this case just one IP address is possible.
2) /24 in CIDR x.x.x.0/24 means fix the first 24 bits and use last 8 bits to form a range of addresses. In this case, there can be 2^8 IP addresses i.e. from x.x.x.0 to x.x.x.255.
3) /16 in CIDR x.x.0.0/16 means fix the first 16 bits and use the last 16 bits to form a range of addresses. In this case, there can be 2^16 IP addresses i.e. from x.x.0.0 to x.x.255.255.
4) /8 in CIDR x.0.0.0/8 means fix the first 8 bits and use the last 24 bits to form a range of addresses. In this case, there can be 2^24 IP addresses i.e. from x.0.0.0 to x.255.255.255.
5) /0 in CIDR 0.0.0.0/0 means fix the first 0 bits and use the last 32 bits to form a range of addresses. In this case, all the possible IP addresses are included in the range.
Hope it helps you in understanding your problem that first 16 bits needs to be fixed in x.x.0.0/16 CIDR.

A CIDR range ending in /16 means the last two numbers can change.
In your case, the range would be: 172.31.x.x
Thus, 171.31.0.0 is not in that CIDR range.
By the way, you probably don't want to create a VPC with a /16 range. It contains over 65,000 IP addresses and would make it difficult to peer with other VPC you might create in future. You could probably use a smaller (eg /22) CIDR range.

Related

What is `10.0.0.1/32` in networking?

What is the difference between 10.0.0.1/32 and 0.0.0.0/0 in networking?
I am trying to fix this security issue by allowing all traffic through port 22 with cidr_block set to (0.0.0.0/0). After research, 10.0.0.1/32 appears to fix this. However, what is the difference in this context?
Here is the issue https://docs.bridgecrew.io/docs/networking_1-port-security.
That is a CIDR block, which denotes a range of IP addresses. The CIDR block 0.0.0.0/0 denotes every IP address that exists, while the CIDR block 10.0.0.1/32 denotes the range 10.0.0.1 to 10.0.0.1 (in other words, the single IP address 10.0.0.1).
You can calculate the CIDR range using a utility like this one.

Error when creating private subnets within AWS VPC

I am currently trying to create a VPC with multiple subnets in AWS. Unfortunately, whenever I go to design the subnets within the VPC I am getting errors. This is my VPC design:
VPC: 10.82.0.0/16
Private Subnets:
10.82.96.0/21
10.82.119.0/21
10.82.194.0/21
10.82.212.0/21
The Error I get is the following for each subnet CIDR except 10.82.96.0/21:
Must be a valid CIDR block.
What am I doing wrong? I just want to create multiple private subnets in this VPC.
A /21 is quite an unusual netmask to be using. It contains 2048 IP addresses.
The netmask for /21 would be:
11111111.11111111.11111000.00000000
Only the zeroes are allowed to change. In binary, 100000000000 is equivalent to 2048 in decimal and 1000 in binary is 8 in decimal.
This means that the second last number would be a multiple of 8 (eg 0, 8, 16, 32).
However, you have not chosen IP addresses that start in a /21 range.
Your chosen subnets would have the following IP address ranges:
CIDR First address Last address
10.82.96.0/21 10.82.96.0 10.82.103.255 Good!
10.82.119.0/21 10.82.112.0 10.82.119.255 Invalid
10.82.194.0/21 10.82.192.0 10.82.199.255 Invalid
10.82.212.0/21 10.82.208.0 10.82.215.255 Invalid
Note that the first line is good because 96 is divisible by 8. Therefore, it is valid in a /21 CIDR.
However, the subsequent lines do not start on a /21 boundary. They are invalid CIDR values.
I highly recommend using a CIDR calculator when determining difficult IP ranges.

Why is 10.0.0.1/28 not a valid subnet within a VPC of 10.0.0.0/24?

How to create Multiple Subnets within Range 10.0.0.0/24.
Tried creating 10.0.0.1/28 . It tells it should be within the CIDR Range.
I am sure am making something wrong . Please advise.
If you have a VPC has : 10.0.0.0/24. then you want to create some subnets are being this VPC.
If you want to create subnet with /28 so:
10.0.0.0/28
10.0.0.16/28
10.0.0.32/28
10.0.0.48/28
10.0.0.64/28
............
10.0.0.240/28
If you want to create subnet with /26:
10.0.0.0/26
10.0.0.64/26
10.0.0.128/26
10.0.0.192/26
The message is misleading. It is not like 10.0.0.1/28 is not within the CIDR range of 10.0.0.0/24, it simply is an incorrect network ID (the message could be slightly more helpful I guess).
You can only specify network ID, not a network address. In your case 10.0.0.1/28 is the first network address from range 10.0.0.0 - 10.0.0.15 where 10.0.0.0/28 is the network ID that you need to use instead. The next network ID for /28 prefix length is 10.0.0.16 as it was mentioned in the other answer.
This is given by subnetting rules. Long story short, if you need to know network IDs then just subtract the prefix, in this case 28 from 32 (32 bits of IPv4 address) which gives you 4 usable bits for hosts which translates to 2^4 = 16 block size. Therefore you can start with 10.0.0.0 and continue by adding 16 to the last number 0, 16, 32, 48, ... and the same goes for the other prefixes as well (or at least if you consider any prefix longer or equal to 24, it kind of works for shorter prefixes as well but you need to be careful which octet of IP address you are modifying).
It is also worth mentioning that the 10.0.0.1/28 is not even a usable IP address on AWS because AWS reserves first 4 and the last one IP address of each subnet (first 4, including network ID, are used for stuff such as DHCP server in your subnet which you don't directly see and the last one is broadcast address which, in general, cannot be assigned to any host, moreover AWS doesn't even support broadcasts).
So technically, when you use 10.0.0.0/28 subnet, you will end up with 11 available IP addresses ranging from 10.0.0.4 to 10.0.0.14.

Number of available IP addresses per private IP address range

I have a problem with determining the correct number of available IP addresses per private IP address range for an AWS VPC for example.
Given that AWS allows assigning a range starting from a /16 block, I have the following available ranges. Given the fact they take 4 addresses away from me, this leaves me with the following ranges:
10.0.0.4 - 10.0.255.254
172.16.0.4 - 172.16.255.254
192.168.0.4 - 192.168.255.254
According to all calculators available on the internet, I get the same amount of IP addresses (65331). Nevertheless I've seen numerous recommendations to choose 10.0.0.0 as the address range, as it provides the highest number of IP addresses. Can somebody clarify this?
Thank you very much
not sure if I understand your question too well, but I will try to shed some light on what you are asking. AWS uses those 4 IPS for their internal routing and configuration of their network.
Example VPC Address Range: 10.0.0.0/16
If you have this CIDR example, AWS takes the first 4 for their own resources of each SUBNET and you have access to the rest of these IPS in the given SUBNETS.
Now we can break that VPC down into smaller subnets so it can be used for different reasons such as the standard ( Pub / Private ).
Example Subnet : 10.0.0.0/27 = 32 IPS
32 - 4 = 28
AWS Also does not support .255(network broadcast address) of a subnet, so they take the last IP as well which gives you a total for 28 - 1 = 27 IPS for use.
Sources: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html

How to validate an invalid CIDR block?

I have the following CIDR reserved for my VPC -> 10.0.0.0/22
What this tells me is that I have 10 bits leftover for my host ips or 1,024 addresses. I was attempting to compute the range of valid addresses, as Amazon asks for a valid IPv4 CIDR block when creating a new private subnet.
I figured 6/8 bits are taken from the 3rd octet and the last octet is all 0's, which leads me with an IP range of 10.0.0.0 -> 10.0.3.255.
As I come to the screen to actually pick my IPv4 CIDR block, I'm getting an "Invalid error", which is just validating that I don't understand how the math is actually working work. I typed in 10.0.2.1/28 which yields a Must be valid Ipv4 CIDR error.
My thought process:
This looked like it was in the range I had calculated and that I wanted my private subnet to reserve 16 IP addresses.
What am I doing wrong?
You are starting with a VPC 10.0.0.0/22. You are correct in that the valid addressing range is 10.0.0.0 -> 10.0.3.255.
Now you want to create a subnet from this VPC using /28 CIDR blocks. /28 means the last four bits are 0 to give you the range 0 -> 15. CIDR blocks must always begin on their own boundary. Examples for /28:
10.0.0.0 -> 10.0.0.15
10.0.0.16 -> 10.0.0.31
You tried to create a subnet with the CIDR block 10.0.2.1/28. This is invalid as it does not begin at offset 0 within the valid CIDR range for /28. You can create a valid subnet as 10.0.2.0/28 or 10.0.2.16/28, etc. Notice how the start of each subnet has the last four bits as 0.
A quick way to look at this is for any subnet, the host portion starts at 0 and ends in all ones.
I just want you to tell you the rules to choose CIDR block as follows:
All the IP address should be in contigious.
The number of IP's you can get is in the power of 2n
First IP address in the block should be evenly divisible by the size of block i.e. (2n).
Third point is important as well as related to second point.
10.0.2.1/28 - It is not the proper CIDR block ID.
As 3rd point here not followed.