49

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.

47

The instance that you launched without a public ip will stay without one as it is only assigned when you launch the instance. Even having a subnet with the 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, the answer to your question is that is not possible to do it after launching that instance unless you use EIPs. I hope this help.

| improve this answer | |
  • 21
    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
  • Now it is possible with AWS new dashboard. Nischal S answer works for me – Maduka Jayalath Dec 18 '19 at 19:01
11

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.

| improve this answer | |
  • 4
    "Launch more like this" eases duplication. – xddsg Dec 6 '16 at 11:07
  • 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 1:07
3

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.

| improve this answer | |
  • This works as long as you have available elastic IPs for the region (only 5 are typically available). – kashiraja Jan 9 at 3:20
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.

| improve this answer | |
  • 1
    But not as the primary interface. – Michael - sqlbot Jul 18 '15 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? – Yaroslav Admin Jul 18 '15 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. – JaredHatfield Jul 19 '15 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. – Yaroslav Admin Jul 20 '15 at 9: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.
| improve this answer | |
  • This doesn't answer the question, the OP specifically asked about assigning a NON-elastic public IP. – shonky linux user Jan 7 '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 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.