Interview Prep/Networking/Cloud networking: VPC, firewalls, NAT, VPN and proxies

An EC2 instance in a private subnet hangs on `apt-get update` at `Connecting to archive.ubuntu.com`.

BeginnerTroubleshootingCloud networking: VPC, firewalls, NAT, VPN and proxies
Answer

Likely causes → The private subnet's route table has no 0.0.0.0/0 route to a NAT gateway, the NAT gateway itself sits in a private subnet (it must be in a public subnet with an IGW route), or the instance SG/NACL blocks outbound 80/443.

Diagnose →

aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=<subnet-id> \
  --query 'RouteTables[].Routes'
aws ec2 describe-nat-gateways --nat-gateway-ids <nat-id> --query 'NatGateways[0].[State,SubnetId]'
curl -m 5 -sI https://archive.ubuntu.com    # from the instance

Fix → Add 0.0.0.0/0 → nat-xxxx to the private route table, place the NAT gateway in a public subnet, and allow outbound HTTPS in the SG.

Prevent → Build VPCs from a tested Terraform module; add a VPC endpoint for S3 so package mirrors on S3 don't need NAT at all.

All Networking questions Roadmap: Networking for DevOps

More on Cloud networking: VPC, firewalls, NAT, VPN and proxies