87

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.

Yaroslav Admin
  • 1,098
  • 1
  • 10
  • 15

6 Answers6

80

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
  • 96,255
  • 29
  • 175
  • 230
estebanc
  • 916
  • 7
  • 3
  • 38
    Sorry for being emotional, Amazon sucks indeed with all these things you can't change afterwards. It's plain everywhere -- can't rename, can't remove, can't assign. Do they use their own system, anyway? :) – Alex Fortuna May 18 '16 at 18:53
  • 2
    Now it is possible with AWS new dashboard. Nischal S answer works for me – Maduka Jayalath Dec 18 '19 at 19:01
17

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.

David Doleman
  • 171
  • 1
  • 2
  • 7
    "Launch more like this" eases duplication. – xddsg Dec 06 '16 at 11:07
  • 1
    Thanks for the "launch more like this tip"! Note that it doesn't retain root volume sizes, though, so you'll have to set those again. – Brandon Dec 21 '18 at 01:07
  • detach the original volume from the original instance and attach it to the newly-provisioned instance (detaching and deleting the volume you provisioned with it, I'd recommend the low default 8GB gp2 drive they suggest at the time of this writing). – danno Apr 05 '23 at 19:55
12

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.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
Nischal S
  • 145
  • 1
  • 2
  • 2
    This works as long as you have available elastic IPs for the region (only 5 are typically available). – kashiraja Jan 09 '20 at 03:20
  • This is a soft limitation so it is possible to request additional elastic IPs for your account – Eralper Jan 12 '21 at 06:14
  • 2
    EIPs are only free while your instance is running. If your instance is in the stopped state, they cost about the same hourly as running a tiny instance. – colllin Feb 10 '21 at 18:40
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
  • 5
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.

JaredHatfield
  • 256
  • 1
  • 5
  • 1
    But not as the primary interface. – Michael - sqlbot Jul 18 '15 at 02:12
  • Just tried your suggestion with no luck. When I create new ENI in the web console it doesn't have an option to enable "Public IP". The defaults from the VPC subnet are ignored as well. Any ideas? – Yaroslav Admin Jul 18 '15 at 08:01
  • If all you want to do is assign an public IP to the server you could use an EIP. Create one through the GUI and then assign it to the server. I may have misunderstood the original requirements with my original response. – JaredHatfield Jul 19 '15 at 00:47
  • Yes, I know that I can use EIP. But as I stated in question, I'm particularly interested in possibility to assign dynamic public IP. The same as I get, when check Auto-assign Public IP when launch new instance. – Yaroslav Admin Jul 20 '15 at 09:36
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
  • 13,812
  • 5
  • 41
  • 55
Ishan H
  • 27
  • 1
  • This doesn't answer the question, the OP specifically asked about assigning a NON-elastic public IP. – shonky linux user Jan 07 '19 at 23:17
  • I know this is not the answer to the question, but it helps others "like me" to search for a solution on google. Thanks – Andres Felipe Mar 18 '20 at 00:00
  • @AndresFelipe I'm searching for a solution for the original question on google and your "not the answer" doesn't help me. – homm May 31 '23 at 10:53