95

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 Answers 6

87

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.

2
  • 39
    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? :) May 18, 2016 at 18:53
  • 2
    Now it is possible with AWS new dashboard. Nischal S answer works for me Dec 18, 2019 at 19:01
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.

3
  • 8
    "Launch more like this" eases duplication.
    – xddsg
    Dec 6, 2016 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, 2018 at 1: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 5, 2023 at 19:55
16

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.

3
  • 2
    This works as long as you have available elastic IPs for the region (only 5 are typically available).
    – kashiraja
    Jan 9, 2020 at 3:20
  • This is a soft limitation so it is possible to request additional elastic IPs for your account
    – Eralper
    Jan 12, 2021 at 6:14
  • 3
    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, 2021 at 18:40
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.

4
  • 1
    But not as the primary interface. Jul 18, 2015 at 2: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? Jul 18, 2015 at 8: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. Jul 19, 2015 at 0: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. Jul 20, 2015 at 9:36
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
1
  • 1
    the title: Assign Public IP (not Elastic IP)
    – manix
    Mar 16, 2022 at 2:54
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.
3
  • This doesn't answer the question, the OP specifically asked about assigning a NON-elastic public IP. Jan 7, 2019 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 Mar 18, 2020 at 0: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, 2023 at 10:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .