Every EC2 server and most AWS databases live inside a VPC (Virtual Private Cloud): your own private network in AWS. Networking questions appear in almost every AWS and DevOps interview, and a wrongly configured VPC is a common cause of “my server is not reachable” problems.
The building blocks
- VPC: a private network with an IP range you choose, such as 10.0.0.0/16.
- Subnets: smaller ranges inside the VPC, each in one Availability Zone.
- Internet gateway: connects the VPC to the internet.
- Route tables: rules that decide where network traffic from a subnet goes.
- NAT gateway: lets servers in private subnets reach the internet (for updates) without being reachable from it.
Public vs private subnets
A subnet is public when its route table sends internet traffic (0.0.0.0/0) to the internet gateway. A private subnet has no such route. Put load balancers and bastion hosts in public subnets, and application servers and databases in private ones.
Security groups vs network ACLs
- Security groups are firewalls attached to instances. They are stateful: if you allow a request in, the reply is allowed out automatically. You only write allow rules.
- Network ACLs apply to whole subnets, are stateless, and support both allow and deny rules.
In practice, most access control is done with security groups. A good habit: let the database security group accept traffic only from the application server’s security group, not from an IP range.
A simple two-tier example
- Create a VPC with two public and two private subnets across two Availability Zones.
- Attach an internet gateway and route the public subnets to it.
- Place a web server in a public subnet, allowing HTTP and HTTPS from anywhere.
- Place a database in a private subnet, allowing its port only from the web server’s security group.
Delete NAT gateways when you finish practising; they are charged by the hour.
Related: AWS EC2 for beginners, AWS IAM explained and AWS S3 for beginners.
AWS networking is covered with labs in our AWS and DevOps course in Bangalore.
Book a free demo class at our BTM Layout centre, and ask a counsellor for batch details.
