VPC Peering if both side VPC CIDR range is same? - amazon-web-services

Is there is any workaround if we have the same vpc cidr (different aws account )at both ends and we want VPC peering? Or any other mechanism which can help me to connect between two same VPC CIDR but in different aws account ??

The peering connection requires non-overlapping CIDRs.
Ensure that your VPCs do not have overlapping IPv4 CIDR blocks. If they do, the status of the VPC peering connection immediately goes to failed. This limitation applies even if the VPCs have unique IPv6 CIDR blocks.
A way to deal with such cases is to use secondary CIDR range. Such setup is exemplified in the AWS doc:
Two VPCs peered to a specific CIDR block in one VPC
In the example, VPC A has overlapping CIDR range with VPC B and C. To establish peering connection, extra CIDR ranges are used.

There is a good article in AWS blog which provides several solutions depending on your needs:
Renumber IP networks
Use AWS PrivateLink
Use multiple IP address ranges in VPCs
Hide subnets using Private NAT Gateway

Related

CIDR added accidently another AWS VPC

I have accidently added a secondary CIDR to a VPC which was already being used by another VPC in another AWS account our company's private network . My question here is if the cidr was already being used , how was I allowed to add again to another VPC ? Also doesn't AWS provide a mechanism to check if the cidr range that we are trying to add is available or being used ?
You can have multiple VPCs with the same CIDR range. This is the benefit of the Cloud! It's great when you want non-production networks to exactly match Production networks. It's a feature, not a failure.
Having multiple VPCs with overlapping ranges will only be an inconvenience if you wish to connect those VPCs together, or you wish to be able to route to both VPCs from the same VPN or Direct Connect connection.

Change the CIDR subnet of GKE cluster

I have two GKE clusters with the same CIDR subnet addresses (the clusters are in different gcloud project). I need to connect the VPC with VPC peering but I get an error because the CIDR subnet and I need to change one. I have a lot of pods, secrets, deployemts...etc. Are any way to change the subnet without creating a new cluster and migrating the pods?
Thanks!
I am afraid you cannot, A subnet CIDR range in one peered VPC network cannot overlap with a static route in another peered network. This rule covers both subnet routes and static routes.

Are there private IPv4 ranges AWS reserves for its use?

When we create a VPC, we generally allocate it a private IPv4 address range as specified in RFC 1918.
I am making an assumption that Internet Gateway, NAT Gateway etc. are hosted on AWS managed VPCs as they are highly available and scalable same like how a customer would design a service on AWS.
Are there private IPv4 ranges AWS reserves for its use to solve overlaps between Customer's VPC and their own VPCs that hosts Internet Gateway / NAT Gateway? How is the CIDR overlaps managed?
It appears that you are asking about overlaps between customer VPCs and the actual networks used to 'run' AWS. However, there is no such overlap.
All networking in VPCs is virtual. Infrastructure deployed within VPCs are given IP addresses from the VPC's CIDR range. For example, a NAT Gateway connects to a VPC via an Elastic Network Interface (ENI), which consumes a private IP address from within the VPC. This allows it to communicate with other resources in the VPC, such as EC2 instances, RDS databases and Load Balancers.
The Internet Gateway does not consume any private IP addresses. It is simply a routing concept between a VPC and the Internet.
The actual equipment that AWS uses to operate services runs on separate networks that exist 'outside of' VPCs.
Yes there are some ways AWS reserves ip addresses in your VPC :).
Firstly, the internet gateway actually does not use up an address in your VPC. The vpc router basically takes care of routes to the internet gateway (more on the vpc router below). I guess that they use all kinds of fancy network overlays and tricks to handle this traffic. Unfortunately I'm not enough of a network specialist to know the exact tech they use for this.
When creating a NAT gateway, AWS actually creates an elastic network interface inside your subnet with a a private ip address attached to it. You can see these when going to the 'elastic network interface' view in the EC2 console. Obviously, you can't reuse these addresses.
Thirdly, aws actually reserves several addresses per subnet. From the aws docs:
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. The IP address of the DNS server is the base of the VPC network range plus two. For VPCs with multiple CIDR blocks, the IP address of the DNS server is located in the primary CIDR. We also reserve the base of each subnet range plus two for all CIDR blocks in the VPC. For more information, see Amazon DNS server.
10.0.0.3: Reserved by AWS for future use.
10.0.0.255: Network broadcast address. We do not support broadcast in a VPC, therefore we reserve this address.
If you create a VPC or subnet using a command line tool or the Amazon EC2 API, the CIDR block is automatically modified to its canonical form. For example, if you specify 100.68.0.18/18 for the CIDR block, we create a CIDR block of 100.68.0.0/18.
So in short, the vpc router takes care of routing requests to AWS internet gateway, NAT gateways get their own elastic network interface and there are some other addresses reserved as well.
Private IP address can reuse in different network and can not be use in public, that's why it is called private.
If you use AWS services and if it is in a VPC, it will get an IP address in your CIDR range. Otherwise, it will allocate in AWS network.

AWS VPC CIDR in both 10.0.0.0/8 and 192.168.0.0/16 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I have VPC A with CIDR 10.A.0.0/16 and VPC B with CIDR 10.B.0.0/16. I have VPC A and B peered and updated the route tables and from a server in 10.B.0.0/16 can ping a server in 10.A.0.0/16 and vice versa.
The applications on VPC A also use some IPs in the 192.168.0.0/16 range. Not something I can easily change, but I need to be able to reach 192.168.0.0/16 on VPC A from VPC B.
I've tried adding 192.168.0.0/16 to the route table used for VPC B and setting the target of the peered connection. That does not work, I believe because 192.168.0.0/16 is not in the CIDR block for VPC A.
I'm unable to add 192.168.0.0/16 as a secondary CIDR in VPC A because it is restricted. See CIDR block association restrictions and related question. I understand it is restricted, but why is it restricted? RFC1918 doesn't seem to say anything against using more than one of the private address spaces.
I've also tried making a Transit Gateway, attaching both VPCs, and adding a static route to the Transit Gateway Route Table for 192.168.0.0/16 that targets the VPC A attachment. But still cannot reach that range from within VPC B.
Is there another way to peer to both 10.0.0.0/8 and 192.168.0.0/16 CIDR blocks on the same VPC?
Updated, background info
The VPCs are used by two different kubernetes clusters. The older one uses project-calico that uses the default cluster CIDR 192.168.0.0/16 and pod IPs get assigned in that range. The newer one is an EKS cluster and pod IPs are assigned from the VPC's CIDR range. During the transition period I've got the two clusters' VPCs peered together.
Route Table
The route table for the private subnet for VPC A
10.A.0.0/16 local
10.B.0.0/16 pcx-[VPC A - VPC B peering connection]
0.0.0.0/0 nat-[gateway for cluster A]
Route table for the private subnet for VPC B
10.B.0.0/16 local
10.A.0.0/16 pcx-[VPC A - VPC B peering connection]
192.168.0.0/16 pcx-[VPC A - VPC B peering connection]
0.0.0.0/0 nat-[gateway for cluster B]
This does not work, of course, because 192.168.0.0/16 is not in VPC A's CIDR block, nor can it be added.
Calico creates an overlay network using the specified cluster CIDR (192.168.x.x) on top of VPC (A) CIDR, so pods/services in this k8s cluster can communicate. The overlay network routing information is neither expose nor usable for AWS route table. This is different from k8s cluster running in VPC (B) which uses VPC CNI that leverage on the VPC CIDR as the cluster CIDR.
Calico BGP Peering offers a way here but it is not going to be an easy route for this case.
Calico nodes can exchange routing information over BGP to enable
reachability for Calico networked workloads (Kubernetes pods or
OpenStack VMs).
If you must achieve pod to pod communication in different k8s clusters and networks but not via Ingress/LB, migrate one of the k8s cluster CNI to be the same as the other so you can fully leverage on their unique peering capabilities.

Is AWS VPC CIDR shared with other accounts?

AWS creates default VPC with CIDR 10.0.0.0/16 or sometimes 172.31.0.0/16.
I created another AWS account & in that also same CIDR blocks were created.
So my question is
If 2 accounts have same CIDR blocks then is my number of subnets available shared by other accounts?
For for application, should I create my own VPC rather than using default one created by AWS?
Appreciate an answer
Two VPCs whether in the same account or different account can have the same CIDR BUT you cannot route traffic between them. ie., if the instances in the VPCs do not communicate.
If you really want to route traffic between them using internal IPs (using VPN etc.,) you MUST use a different CIDR, same account or different account does not matter.
If you have the same CIDR, the routing table will route the traffic internally when you intend to route it to the other VPC.