Can I remove the public IP on my instance without terminating it?
Nope that is not possible without terminating the instance. If it was Elastic Ip then it would have worked.
The only option is Take AMI of the instance, terminate the instance and launch the AMI in the VPC without enabling Public Ip address for that instance.
Once you terminate the instance with that private IP you can assign that private ip again to a new Instance you created from the Image. (As long as it's in the same VPC and subnet) This way you don't need to update the private IPs off all the "instances on a vpc that communicate with each other through their private ips"
Steps worked for me:
- Disable auto assign public IP setting on vpc subnet.
- Stop the ec2 instance.
- Open Network Interface Manage IP address settings and assign a secondary private IP.
- Open Elastic IPs and associate an elastic IP to the ec2 with secondary private IP.
- Start the Ec2 Instace.
- Open Network Interface Manage IP address settings and unassign the secondary IP.
- Done, now you can release the previously associated elastic IP.
Yes you can remove a public IP address from an instance.
This solution applies when your instance was launched in a subnet with the "auto-assign public IP" setting enabled. This makes AWS add a public IP address that seems hard to remove.
Notes:
- If you change the subnet auto-assign setting and stop and start the instance, this does not work, it has no effect. The public IP remains.
- If you got your public IP by associating an elastic IP then it's a different case and easy to fix; all you need to do is right-click on the instance or on the Elastic IP, and choose "Networking", "Disassociate Elastic IP Address")
There is a voted-down solution here that seems to work at first, but the public IP comes back (as a different address) when you start the instance up again.
Solution: (detailed steps below)
You need to first add another Network Interface, (so there are two or more N.Is), then you can release the public address by adding and removing an elastic IP.
Here is a detailed step-by-step guide:
- Create a new network interface.
- Attach the new network interface to your instance. Now there will be two or more network interfaces attached to your instance. This is important. There MUST be two or more for this to work.
- Create a new Elastic IP (in the EC2 console).
- Right-click on the new EIP and associate it to the instance whose public IP you want to remove. The original public IP will be replaced by the new one.
Now do the reverse of step 4, disassociate the EIP you have just added. At this point, right-click on the instance and select "Networking", "Manage IP addresses", you will see there are no public IPs on you instance any more. at this point. You must refresh the instances view otherwise you will not see this.
The public IP is now gone for good. Even if you stop and start the instance, it will not return.
Tidy up: delete the elastic IP you created earlier. Don't delete the new extra Network Interface. This has to stay in place. If you remove the new / second NI then the public IP will come back the next time you stop and start the instance.
I know this sounds a bit strange, but it is in the AWS docs here and I've tested it and it works.
The relevant part from the AWS documentation on that page, is this: "If the public IP address of your instance in a VPC has been released, it will not receive a new one if there is more than one network interface attached to your instance."