Configuring Public IP for EC2 Instances in a Custom VPC

Enable Auto-Assign Public IP for EC2 Instances in a Subnet

Prev Question Next Question

Question

You have created a custom VPC and created a subnet.

You have launched an EC2 in the subnet and selected Auto-Assign Public IP as "Enabled"

You noticed after the launch of the EC2 Instance that EC2 instance has not been assigned to any public IP address.

What changes need to be done to ensure the EC2 instance can get a public IP address.

Chose 2 answers from the given options.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer: A & C.

The requirement is EC2 instance is already launched and Public IP has not been assigned even while creating instance Auto-Assign Public IP was selected "Enabled"

Now we need to take further action so that EC2 get public IP.

To do this our approach should be check

1

IGW has been assigned to VPC.

2

EC2 instance should be launched in public subnet.

Option D: since instance has already been launched going back is absolutely no way to take any further action.

Option B: While launching EC2 instance, "Auto-Assign Public IP" has 3 option

1.use the subnet setting (Enabled)

2

Enabled.

3

Disabled.

Since we have already selected "Enabled" so this option is not a possible answer.

To enable an EC2 instance to obtain a public IP address, you need to ensure that:

  1. An Internet Gateway is attached to the VPC: An Internet Gateway (IGW) is required for communication between your VPC and the internet. The IGW serves as a gateway to the internet, and it must be attached to the VPC that contains your subnet.

  2. Auto-Assign IP4 attribute for the subnet is "Enabled": When Auto-Assign Public IP is enabled for an EC2 instance, the subnet's Auto-Assign IP4 attribute must also be enabled. This setting allows the EC2 instance to receive an IP address from Amazon's public IP address pool when it is launched.

So, the correct answers are A and B.

Option C, ensuring the EC2 instance is in a public subnet, is not necessary to obtain a public IP address. Public and private subnets are determined by their route tables.

Option D, ensuring the Public IP setting is enabled for the EC2 instance during launch time, is already done as per the question statement. The issue is that the EC2 instance has not been assigned a public IP address despite the setting being enabled, so the problem is not related to this option.

In summary, you need to ensure that an Internet Gateway is attached to your VPC, and the Auto-Assign IP4 attribute is enabled for the subnet where the EC2 instance is launched.