1

Since February 1, 2024, AWS started charging for public IPv4 and I have several EC2 instances.

Some instances I can having only public IPv6, for others I need to keep public IPv4. I disabled Elastic IP and type A addresses for one instance for testing. However, when I remove public IPv4 from an instance, it stops accessing IPv4 internet. IPv6 internet works fine, and it still keeps a private IPv4.

From what I understand, I should create a NAT gateway, but I don't see how I can do this without changing the instance's VPC or subnet and for that I need to terminate the instance and create another one, which complicates the process too much.

What is the step-by-step procedure to disable public IPv4 on an instance without breaking anything? What am I missing?

1 Answer 1

1

This method works to remove a public IP, I've tried it myself. I've added a copy / my own notes on how to do it below in case the link changes.

A NAT gateway allows an instance with only a private IPv4 address to reach the IPv4 internet. Of course a NAT gateway costs significantly more than an IPv4 address, so it only makes sense if you have 3 or 4 instances. You don't need to change anything about your instance to use a NAT gateway, you simply deploy your NAT gateway to a public subnet and route internet traffic to it. There are many tutorials, this one looks like it should work.

  • Go to your running EC2 instance with the public IP you want to remove. Note what region and availability zone are associated with that instance.
  • On the left-hand panel, scroll and go into “Network Interfaces” under the “Network and Security” Dropdown. Once there, click “Create Network Interface.” In the description, give it a memorable name (we used “TEST 1b” in this example). For the subnet, pick a matching one for the instance from Step 1. Click “Create” to finish.
  • Next, go it elastic IPs (also under the “Network and Security” Dropdown). After you create a new elastic IP, associate it with the EC2 instance.
  • Next, go back to your running EC2. Right-click it and select “Attach Network Interface” under the “Networking” option
  • From here, attach the network interface made previously.
  • Next, disassociate the elastic IP from the instance. If done properly, the public IP should disappear.
  • Release elastic IP address
  • Remove network interface from instance

You must log in to answer this question.

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