[Updated 2018-06-11.] You can assign multiple IP addresses to an EC 2 instance. Here is a brief summary that will get you started on using the most recent AWS capabilities.
Multiple IP addresses are a requirement for multiple SSL certificates and have a variety of other useful applications.
A brief introduction to EC2 networking
Every instance on EC2 can have up to 15 network interfaces (depending on instance type) with one or more IPs each. If you assign any network interfaces in addition to eth0, AWS will disable the auto-assign public IP address feature.
Network interfaces in EC2 are detachable, so you can easily swap them and their associated IPs between running EC2 instances. Every network interface has the ability to expose public IPs (a subclass of which are Elastic IPs or EIPs) to the world outside and private IPs to the system running your instance. A security group applies to the network interface. By extension, it also applies to all of the associated IPs for as long as they remain associated with it.
Every network interface on EC2 can have two private IPv4 addresses (from that network interface’s subnet). In addition, it can have multiple IPv6 addresses (all of those must belong to one subnet as well).
If you want to use IPv6 addresses on a network interface in EC2, you must associate an IPv6 CIDR block to a subnet. Next, you must also put that network interface in that subnet.
After assigning a private IP address to your instance, you need to configure the operating system to recognize it (except for the primary IP on the primary interface). That’s the hard part.
Assigning multiple IP addresses to an EC 2 instance
Assigning multiple IP addresses to an EC 2 instance involves passing User data to your instance: either cloud-init configuration details or a shell script for execution.
Step 1. Figure out the desired specs of your instance
To assign multiple IP addresses to an EC2 instance, you need to first figure out the instance type you need based on the desired specs (for RHEL/Fedora/Centos, see section “IP Addresses Per Network Interface Per Instance Type” in this document).
Step 2. Set up your network interfaces
Then, create your network interfaces. Make note of their Private IPs.
Step 3. Code your User data script
For details on how to write your user data, see the description here. For an explanation on the type of networking setup you are looking for, read „Multiple EC2 Network Interfaces on Red Hat/CentOS 7“. Make sure you read the comments as well.
Step 4. Write User data to your instance
Next, you can do one of two things: either launch a new instance or change user data of an instance you have previously initialized (stop, edit user data, restart).
Option 1. Launch a new instance. When you launch a new instance, you specify the network interfaces and a user data script that configures them in Step 3 „Configure Instance Details“ of the EC2 wizard. By selecting an existing network interface, you define the Private IP. As a result, you now have the ability to configure the system by passing User data onto cloud-init.
To select which network interfaces AWS will connect to the instance, specify them in „Configure Instance Details“. In the section „Advanced Details“, enter your user data script that will set up your networking.
Option 2. Edit user data of an existing instance. When you decide to change user data of an instance you have already initialized, stop the instance, edit its user data, then restart.
In addition, here are some useful resources:
- Amazon’s explanation of what you can do with multiple IPs on EC2
- Assign a floating (secondary) IP address in AWS VPC
- use an AWS CLI Script to Assign a Secondary IP
- IP addressing in a VPC
- Multiple EC2 Network Interfaces
- configure cloud-init in user data at launch
- this discussion on step-by-step configuration of a secondary ip address on an amazon linux vpc instance
Also, a script called Aliaser by Josh Wieder can help resolve ongoing issues with IP aliasing when using Amazon EC2 virtual machines without the benefit of ec2-net-utils: