Are there restrictions on what IP ranges can be used for a VPC? And what do I do if I run out?

First I must admit that this part of AWS/networking is still a bit fuzzy in my head.

When making a VPC there are 3 ranges that are suggested, but presumably there are more.

Can I make up new prefixes like 123.456.0.0 or is there set list of prefixes I can’t see that includes more than these 3, or is it basically these three?

To quote AWS:

When you create a VPC, we recommend that you specify a CIDR block from the private IPv4 address ranges as specified in RFC 1918.

RFC 1918 range Example CIDR block

10.0.0.0 - 10.255.255.255 (10/8 prefix) 10.0.0.0/16

172.16.0.0 - 172.31.255.255 (172.16/12 prefix) 172.31.0.0/16

192.168.0.0 - 192.168.255.255 (192.168/16 prefix) 192.168.0.0/20

If I can only work with these 3, and they’re all used what options do I have?

Would I need to reduce the available blocks via the CIDR block stuff? (which I’m starting to grasp but not fully)

-—

EDIT:

When I say “used up” I should clarify that there are 3 vpc’s in the account and they each use the 3 prefixes named above - ie:

VPC-1: 172…

VPC-2: 192…

VPC-3: 10…

And now I’m looking to add another VPC so I don’t know whether I should find a new prefix or break one of the older ones up.

What do you mean they are all used up? Your company has already allocated that many IP blocks? I suppose I could see default routes to 10./8 being set but they should just fix that. You could use other blocks, but unless you own it you would be creating a confusing mess down the road, and obviously would not be able to route to the people that actually own that IP space. The rfc blocks are designated for private uses on private networks like a private vpc - there are no more. You can use whatever you want, but it would be a really bad idea. I would have a chat with your network engineers and get some 10./8 space for you, and while you are at it allocate enough for multiple AZs and multiple regions, preferably contiguous to make life easy if you end up with direct connect, etc just to simplify routing.

You should keep your prefixes within those ranges, but you will likely not run out if you use the recommended subnet for each (/16 in the case of 10/8). VPC1 can be assigned 10.0.0.0/16 which is 10.0.0.0 - 10.0.255.255. VPC2 can be assigned 10.1.0.0/16 which is 10.1.0.0-10.1.255.255. And so on and so forth.

The following is a subnet calculator: https://www.wmtips.com/tools/subnet/

I suggest you type in a couple of the recommended CIDR ranges and see how many addresses are available.

Do you honestly think that you’ll run out of internal IP addresses?

Note that you can reuse the private IP addresses in separate VPCs (as long as you don’t plan on connecting them to each other).

That’s nearly 18 million IP addresses in those private ranges. I don’t think you’ve run out. sounds like you have a different problem.

Edit: See much much more thorough comment here https://www.reddit.com/r/aws/comments/yjcsz9/comment/iupkctn/

You can “technically” use any IP CIDR you want for a VPC, it just needs to be a /16 or smaller (and bigger than /28). It doesn’t even need to be a non-routable RFC 1918 CIDR, you can use public IP range to (this does not make those IPs actually routable publicly, so you don’t typically want to do this as it’s just confusing). You can also have multiple VPCs with the same CIDR as long as they aren’t being peered together.

Eg
10.0.30.0/24
8.10.0.0/16
123.123.123.0/26

All all valid CIDRs you can use for your VPC

Edit:
Marketlurker below makes a good point, just because you can use any CIDR doesn’t mean you should, it’s definitely worth spending the time to think about how many IPs you need, subnet layout, future expansion, how many AZs, peering, etc.

Example:
Running in a single region with 2 AZs, running 50 EC2 nodes per AZ, you could do something like this:

VPC: 10.0.0.0/22 (covers 10.0.0.0-10.0.3.255)

Az1-priv-subnet: 10.0.0.0/24

Az1-pub-subnet: 10.0.1.0/24

Az2-priv-subnet: 10.0.2.0/24

Az2-pub-subnet: 10.0.3.0/24

Each subnet could support 250 interfaces (AWS needs first 5 and last 1 of subnet I believe), private subnets are just those with no route to internet gateway, public subnet does have route to internet gateway. could place things like load balancers or Nat gateways in public subnet and servers in private. (You don’t need sperate priv/pub subnets, it’s just a security best practice)

They might not have that many blocks, so much as someone who hogged entire ranges to run a few instances in each.

No kidding. Holy crap. If you’ve genuinely used all those IPs I want to see your bill.

When I say “used up” I should clarify that there are 3 vpc’s in the account and they each use the 3 prefixes named above - ie:

VPC-1: 172…

VPC-2: 192…

VPC-3: 10…

And now I’m looking to add another VPC so I don’t know whether I should find a new prefix or break one of the older ones up.

(added this as an edit)

Sorry yes that was misleading now I realise.

So basically I have 3 vpc’s and I know of 3 ip ranges which have been used for each of the VPC’s but I think if I’m infering correctly from the other comments, then I can still reuse one of these somehow but I don’t see how yet.

‘Used up’ is only a problem if the VPCs need to talk to each other via private IPs, otherwise you can have any number of VPCs with the same IPs.

Also, IPv6 is great and you can use that to do cross-VPC connectivity even when the IPv4’s overlap.

Sounds like the creator of the VPCs didn’t understand how networking works. I’d make a plan to scrap those VPCs and start over with appropriate CIDRs based on your actual needs.

Yeah. Avoiding that is the reason they make you study subnetting to begin with.

Man you need to clarify yourself what a network is

What is the business case that is driving multiple VPCs? What connection and isolation problems are you trying to solve? Probably there are other, better solutions.

Oh interesting! So does that mean that I could in theory have 10 versions of 192.168?

Well your VPC shouldn’t use the ENTIRE range, you should be using smaller blocks out of those ranges based on the requirements of the VPC. So one VPC can use 10.0.0.0/24, and another can use 10.0.1.0/24 and so on and so fourth.

If you’re using the entire 10.0.0.0/8 range, you’re allocating 16,777,216 IP addresses to that VPC, which is just ridiculous

Fair question/point.

I have a Dynamo DB table and I am putting DAX in front of this. Everything that runs the app is being deployed via Serverless which runs through Cloudformation. So I have had to create a VPC for this setup as per the sketchy documentation and bits of internet I could gather, and now have YML for a Route Table, Subnets, VPC etc.

Now this is all just for my dev environment. I had a pang of terror realising I needed to do this for Prod with a whole new VPC but with the existing VPC’s, I now have three VPC’s and this confusion over adding more vpc’s or what.

Perhaps I need to make make my DAX part on a new stack. That would make sense really. :thinking:

I wish I had had this foresight :slight_smile:

Yes that was just to sort of put out there an address that was obscenely custom just to work out which bits of it can be. But you did alert me of my ignorance with networking that helps a little bit push me in the right direction. Thanks!