All checks
Medium EC2 · regional

EC2 subnets should not automatically assign public IP addresses

Flags EC2 subnets configured to automatically assign public IPv4 addresses or IPv6 addresses to instances at launch, which gives new instances there a publicly routable address by default, whether or not they need one. The setting applies only at launch.

service
EC2
severity
Medium
scope
evaluated in every region

How to fix it

In the console

VPC → Subnets → the subnet → Actions → Edit subnet settings → Auto-assign IP settings

With the AWS CLI

aws ec2 modify-subnet-attribute --subnet-id <subnet-id> --no-map-public-ip-on-launch --region <region>

With Terraform

resource "aws_subnet" "this" {
  vpc_id                          = var.vpc_id
  cidr_block                      = var.cidr_block
  map_public_ip_on_launch         = false
  assign_ipv6_address_on_creation = false
}

See which of your accounts this check is failing on.

Book a demo