How do I assign a custom primary private IP address to my Amazon EC2 instance?

3 minute read
0

I want to assign a custom primary private IP address to my Amazon Elastic Compute Cloud (Amazon EC2) instance.

Short description

To associate a custom private IP address to your Amazon EC2 instance before you launch the instance, the IP address must meet these conditions:

  • The IP address must have a valid IPv4 range.
  • The IP address must be within the CIDR range of the specified subnet.
  • The IP address must be available. The private IP address must not be tied to any other resource.

Resolution

Assign a custom private IP address to an Amazon EC2 instance

  1. Configure an Amazon EC2 instance. For more information, see Launch an instance using the old launch instance wizard or Launch an instance using the new launch instance wizard.
  2. In the Configure Instance Details section, complete the following steps:
    • For Network, select an Amazon Virtual Private Cloud (Amazon VPC) or create a new Amazon VPC.
    • For Subnet, select the subnet or create a new subnet where you want to launch your instance.
  3. In the Network interfaces section, for Primary IP (the primary private IPv4 address of the network interface), enter the custom private IPv4 address.
  4. Complete the launch instance wizard configurations, and then launch the instance.

Note: The private IP address attached to the primary network interface of your Amazon EC2 instance can't be changed when it's launched. Also, the primary elastic network interface can't be switched with another network interface. The elastic network interface is attached to the instance until it's closed.

Create an AMI backup to use a different private IP address with an Amazon EC2 instance

To use a different private IP, create an AMI backup and launch a new instance:

  1. Open the Amazon EC2 console.
  2. Create an AMI with the instance of the private IP address that you want to change. For more information, see Create a custom Windows AMI.
  3. Close your original Amazon EC2 instance. Make sure you note the Amazon VPC ID and subnet ID that the instance was associated to. Make sure that the private IP address that you want to use is within the CIDR range associated with the same subnet.
  4. Launch a new instance from the AMI that you created in Step 2.
  5. From Network settings, complete the following:
    • Edit and select the same Amazon VPC and subnet that was noted in step 3.
    • Select Advanced Network configuration and navigate to the Network interfaces section. Choose the associated Primary IP textbox next to eth0(Device Index 0) and enter the Private IP that you want to use.
  6. Complete the Wizard that you're using, and then launch the new instance. The new instance has the desired private IP address and retains the original instance data.

Related information

VPCs and subnets

AWS OFFICIAL
AWS OFFICIALUpdated 7 months ago