Why is there no Internet Connectivity on an EC2 Instance?

TL;DR; For an EC2 instance in a public subnet the instance must have a public IP address to access the internet, either a Public IP allocated when creating an instance, or an Elastic IP Address. This is probably one of those things that's so obvious it doesn't need to be said, but having been caught out by this several times now thought it was worth blogging about for the next time I make this mistake!

The scenario involves a VPC with multiple subnets, one public subnet (a subnet with a route to an Internet Gateway), and private subnet(s) (with route tables pointing internet traffic via a NAT instance in the public subnet).

An instance in the private subnet will have internet access as it is routed via the NAT (and so outbound traffic is via the NAT instance, which has a Public IP). An instance in the public subnet will not be able to connect to the internet without a Public IP address. So if you have an instance in a Public Subnet and have no internet connectivity, check that a Public IP is assigned to the instance!

  • Post
  • Aftab Naveed
    Aftab Naveed

    That really helped after associating public IP, thanks for your help.

  • swa
    swa

    if EC2 instance is in private subnet then and not able to access internet , what should i check ? using Nat gateway

  • swa - If it's in a private subnet and your using NAT Gateway the first thing to check would be the VPC routing tables for the private subnet - will need to make sure all external traffic "0.0.0.0/0" is pointing to your NAT Gateway.