Manu
Manu

Reputation: 101

Enable auto-assign public IPv4 address in AWS

After creating a new VPC and creating a new subnet, In the subnet settings there is an 'Enable auto-assign public IPv4 address' option.

So if I create an instance in this subnet, will that instance doesn't have any public IP if its not Enabled? What does the option actually mean?

Upvotes: 5

Views: 16810

Answers (3)

ericx
ericx

Reputation: 834

Amazon overloads the words "public" and "private" in very annoying ways. Both "public" and "private" subnets within AWS actually use RFC 1918 "private" addresses (despite the names AWS uses for subnets).

The distinction is that a "private" AWS subnet has a default route to a NAT gateway (NATGW) and all the instances have access to the Internet via a shared NAT pool.

A "public" subnet, on the other hand, will use a "fixed" (as long as the machine is running) "public" (this time, AWS is using "public" in the RFC 1918 sense of the word) AWS IP address and configure it as a 1:1 NAT so that that machine can be reached from the Internet. In order for the latter to work, the subnet needs a default route to an Internet Gateway (IGW) instead of a NATGW and you probably want 'Enable auto-assign public IPv4 address' just to make things easier.

Why would you leave it off? You can optionally tick a box when creating an Instance to assign an external IP. Or you can assign an EIP. Or maybe you want to use load-balancers and assign the external "public" IP to that instead of your instance.

So 'Enable auto-assign public IPv4 address' is an option you most likely want to turn on for your AWS "public" subnets. It has no purpose in a "private" subnet.

Upvotes: 0

In One public subnet, there can be many ec2-instance (machines). Each of them has a different Private IP address.

They need a common address over the internet, for this reason, we give a public address to the whole subnet, using the option "Enable Auto Assign IPv4 address"

Below I am attaching a reference image that may help you understand the concept better.

enter image description here

Upvotes: 3

Ervin Szilagyi
Ervin Szilagyi

Reputation: 16785

When you launch an instance in a subnet, it will receive a private IP address (for example something from the range of 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16). Optionally, you can have a public IP address as well attached to the network interface of the instance.

The public IP can be received in two ways:

  • Allocate an Elastic IP address and manually attach it to the instance;
  • Enable auto-assign public IPv4 address option and receive a public IP address from the Amazon pool.

If you enable auto-assign public IPv4 address, your instance will automatically receive a public IP address at launch. This IP address does not count as an Elastic IP, meaning that it wont decrease the number of available Elastic IP addresses for your region. Also, it will be automatically released if you stop, hibernate or terminate the instance (and in a few other cases, see the docs). Since this IP is not really allocated to you as a persistent IP address, it is not the best idea to rely on this IP address for any production usage (firewall whitelisting, DNS records, etc.).

Upvotes: 15

Related Questions