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.
- Select the instance, then choose
Actions > Manage Private IP Addresses
- In the Manage Private IP Addresses dialog box, Click
Assign new IP
- 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)
- (Optional) Select Allow reassignment to allow the secondary private IP address to be reassigned if it is already assigned to another network interface.
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:
ip addr add PRIVATE.IP.ADDRESS/20 dev eth0
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)
Add the following line to the end of the file:
up ip addr add PRIVATE.IP.ADDRESS/20 dev eth0
Step 3 – Assign an Elastic IP
- In the AWS Console, choose
- Allocate a new IP or choose an existing one, and select
- Choose the instance, and for the
Private IP Addressbe sure to select the new private IP that was created in step 1
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.
ip addr list dev eth0
Removing a private IP from the instance
This command will remove an IP address:
ip addr del PRIVATE.IP.ADDRESS/20 dev eth0
Be sure to remove the associated line in
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.