Hi guys I’m struggling to understand sub-netting in AWS. I understand how public and private subnets work and how to create them and i know that each subnet has its own routing table. My problem is that i dont understand how a private subnet where a back-end or DB is can communicate with front-end in a public subnet as in the routing table , the only ip address is of the vpc itself. So assuming a vpc of 10.0.0.0/16 , public subnet of 10.0.0.0/24 and private subnet of 10.0.1.0/24 , the only ip in the routing table of each subnet is 10.0.0.0/16 . Sorry if its an easy question but i spend days trying to figure out without any luck and im a slow learner.
The best analogy I can think of would be to look at the routing table as a router that has an interface on each subnet. The route that you see for 10.0.0.0/16 has the destination as local, so in a physical router that would be like “directly connected”. It’s not exactly the same, but logically associating the subnet with the routing table is similar to putting a router interface on the subnet in a traditional network.
One thing to note, if that’s the only route for your public subnet, then it’s not actually public. You need a 0.0.0.0/0 route to an IGW in order to make it public.
That said, it seems like maybe you’re not understanding the concept of CIDR block notation. 10.0.0.0/16 isn’t a single IP address, it is just a shorthand way of saying “every IP address that starts with 10.0”. So really you have ~65k IP addresses listed in your route table. The destination for all of those is local to the VPC so if a DB in the private subnet sends a packet to 10.0.0.100, the route table says send that to the instance with that IP within this VPC. There’s no way to override the routing for the CIDR block of the VPC itself. No matter what subnet you are in all traffic to any IP that starts with 10.0 will get routed within the VPC.
All subnets within your VPC have routes to each other by default, you don’t need to configure that. And that is exactly what you saw in your routing table because 10.0.0.0/16 includes both 10.0.0.0/24 and 10.0.1.0/24 and all other 10.0.0.0 subnets with mask lower than 16
No, there’s no way to add a more specific route for the local VPC CIDR. Any IP within the VPC will always route locally. You can add NACLs or security groups to stop certain traffic, but the routing is set in stone.