100

When I launch instance in AWS console I can set "Auto-assign Public IP" to true and newly created instance will be assigned with public IP address from pool.

Now assume I have launched instance with this setting set to false and want to assign public IP to this instance. The same public IP as in first case, not Elastic IP.

PS I know I can launch new instance and shut down old one. I'm particularly interested in assigning to one already running.

6 Answers6

91

The instance that you launched without a public IP will stay without one as it is only assignable when you launch the instance. Even having a subnet with auto assign public IP switched on will not assign a public IP to your instance if, when you launched the instance you chose not to have a public IP.

The only way I know is to select assign a public IP before launching the instance or having the subnet set up to auto assign public IPs which will do that only when you launch a new instance.

So to summarize: It is not possible to assign a public IP after launching that instance unless you use EIPs.

womble
  • 98,245
estebanc
  • 1,026
18

To correct it afterwards, spin down your original server, spin up a new with auto assign public IP enabled and the existing volumes attached.

You can then discard the original instance.

17

If you are using ELB and Autoscaling, creating instance on fly and to stress test the instance is difficult. One solution during this scenario:

Select EC2 instance> Actions>Networking> Manage Ip Addresses. Then use option "To add or edit an IPv4 public IP Allocate an Elastic IP to this instance or network interface".

  1. Create an elastic IP
  2. Navigate to Elastic IP address link> click Associate IP
  3. Select the instance to associate IP and save.

Now you will have EC2 instance with public IP without restarting/deleting EC2 instance.

Nischal S
  • 203
2

This was not possible back in 2016 but now of course AWS allows it:

  1. Go to EC2 view from your console and click on Elastic IPs enter image description here
  2. Click associate ElasticIP enter image description here
  3. Find the EC2 instance that you would like enter image description here
grepit
  • 127
2

Assuming your instance is running in a VPC you can create an Elastic Network Interfaces (ENI) that has a public IP assigned to it then associate that ENI with your instance without needs to create a new one.

1

To assign a public IP to instance at run time:

  1. Click on instance and select Networking-->Manage IP Addresses from action dropdown
  2. Select Allocate elastic from "To add or edit an IPv4 public IP Allocate an Elastic IP to this instance or network interface." line then it will create a public IP for you
  3. A window will appear asking to assign IP created in step 3 to instance and to private IP. Provide the required value.
  4. Now try to ssh via putty. It worked for me. Hope it will help. Best of luck.
kubanczyk
  • 14,252
Ishan H
  • 27