How to Add Additional Elastic IPs to AWS EC2 Instances

Despite what some say, There are several good reasons that you might want to have multiple IPs assigned to one server. If you’re using an AWS EC2 Linux instance then adding additional IPs is fairly simple. Here’s how it’s done.




Step 1 – Add Another Private IP to the Instance

The first step is to add a new private IP. This has to be done because private IPs can only have one Elastic IP assigned to them.

  1. Select the instance, then choose Actions > Manage Private IP Addresses
  2. In the Manage Private IP Addresses dialog box, Click Assign new IP
  3. Enter a specific IP address that’s within the subnet range for the instance (or just leave the field blank to have it choose one for you)
  4. (Optional) Select Allow reassignment to allow the secondary private IP address to be reassigned if it is already assigned to another network interface.
  5. Click Yes, then Update, and finally Close.

Step 2 – Add Private IP to Network Interface

SSH into your instance and run the following command to add the new private IP to the instance’s network interface. Replace PRIVATE.IP.ADDRESS with the new private IP that was created in step 1:

The new private IP address will now work, but it will be removed if the instance is rebooted. To make the new IP persistent it needs to be added to the network device’s conf file. Open (or create) /etc/network/interfaces.d/eth0.cfg:

Add the following line to the end of the file:




Step 3 – Assign an Elastic IP

  1. In the AWS Console, choose Elastic IPs
  2. Allocate a new IP or choose an existing one, and select Associate Address
  3. Choose the instance, and for the Private IP Address be sure to select the new private IP that was created in step 1
  4. Click Associate

Notes

Checking if the ip was added

Use the following command to make sure the private IP was properly added to the instance. The new IP will be listed in the results if all is well.

Removing a private IP from the instance

This command will remove an IP address:

Be sure to remove the associated line in /etc/network/interfaces.d/eth0.cfg.

Amazon’s Imposed Limits

Amazon imposes a limit on the number of IPs that you can have per network interface. The limits are pretty reasonable though, so they likely won’t be an issue.

One response to “How to Add Additional Elastic IPs to AWS EC2 Instances

  1. Very helpful tutorial, thank you! Elastic IPs are a terrific feature.
    I was able to skip Step 2, as the new private IP was automatically added to the Instance’s network under ‘Secondary private IPs’ when assigned to my EC2 Amazon Linux Instance through the service console.
    Then it was just a matter of allocating a second Elastic IP and assigning it to the [Instance’s] new secondary private IP.
    After updating domain DNS settings with the second Elastic IP and updating custom settings in Apache’s httpd conf, it was routing traffic within minutes .

Leave a Reply

Your email address will not be published. Required fields are marked *

×Mike Everhart

Need Some More Help? Let's Talk!

I'd love to work with you! Fill out the form below to schedule a free consultation to discuss your needs and how I can help.

Need More Help?