How do I change the primary private IP address of my Amazon EC2 instance?

2 minute read

I want to change the private IP address of my Amazon Elastic Compute Cloud (Amazon EC2) instance.


When you launch an Amazon EC2 instance in a subnet, the instance receives a primary private IP address from the subnet's IPv4 address range. If you don't specify a primary private IP address, then an available IP address in the subnet's IPv4 address range is assigned to the instance. Every instance has a default elastic network interface (eth0) that's assigned the primary private IPv4 address.

You can't change the primary IP address of an instance after you launched the instance. All private IPv4 IP addresses continue to be associated with the network interface of the instance until you terminate the instance. This is true if you use primary or secondary IP address for your instance. For more information, see Private IPv4 addresses.

Instead, launch a new instance and then assign the preferred IP address:

  1. Create an Amazon Machine Image (AMI) of your instance.
  2. Launch a new instance from the AMI.
  3. To assign the preferred IP address to your new instance from the same subnet, edit the Advanced network configuration when you launch the instance. Then for Primary IP, enter the IP address that you want to use.

You can also exchange the IP address from an existing EC2 instance to another instance. You must change the network interface termination behavior of the instance whose IP address you want to use. By default, Delete on instance termination is turned on for EC2 instances.

To exchange the IP address of an existing EC2 instance to another instance, complete the following steps:

  1. Open the Amazon EC2 console.
  2. Choose Network Interfaces, and then choose Actions.
  3. Choose Change Termination Behavior, and then clear the box for Delete on termination.
  4. Create an AMI of the instance, and then terminate the instance.
  5. Launch a new instance from the AMI.
  6. In the launch wizard, for Network Settings, choose the same VPC and subnet that your terminated instance used.
  7. Expand Advanced network configuration. Then, under Network interfaces, select the terminated instance's network interface from the dropdown menu.
  8. Launch the new instance.

Related information

Amazon EC2 instance IP addressing

AWS OFFICIALUpdated 5 months ago