Setting up dual public IP for AWS EC2 is easy. It's just several clicks in AWS Web Console and a config file inside EC2 away.

Setup Dual Public IP in AWS Web Console

In AWS EC2, each instance is assigned one or more private IPs, where each of these private IPs can be associated with one or zero public IP.

  1. To setup dual public IP for an EC2 instance, we assign it with two private IPs first;

    That is one more assignment actually as there is already one by default.

    AWS EC2 - Instances - "Networking -> Manage IP Addresses" Context Menu

    AWS EC2 - Instances - "Manage IP Addresses" Dialog

  2. Allocate two Elastic IPs and associate each of them to one of the instance private IP.

    If you've already using EIP, only one more EIP is needed.

    AWS EC2 - Elastic IPs

Now, we've done with our work on AWS Web Console.

Use ping to check that only our first public IP actually works. We have more work to be done inside our EC2 instance.

Config EC2 instance to recognize the extra IP

As we've said previously, each EC2 instance is assigned private IPs. As a result, that private IP is what we'll use in the config file.

The configuration process may vary for different distributions.

If you are using Amazon Linux, the ec2-net-utils package can take care of all the things. Otherwise, you need to do it yourself. Check the doc for more info.

Assuming CentOS or RHEL, create /etc/sysconfig/network-scripts/ifcfg-eth0:1 with the following content:

BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
IPADDR=
NETMASK=255.255.240.0

Put your secondary private ip in the IPADDR= line, the one not yes listed in ip addr show eth0 output, NETMASK= line may also need to adjust accordingly.

After that, run

ifup eth0:1

to bring the new config in effect. And use ping to test connectivity.

Pricing

Note that the extra Elastic IP comes with a price while the first EIP associated with a running instance is free.

See EC2 Instance Pricing – Amazon Web Services (AWS) for pricing details.

It's listed as the following in all regions at the time of writing:

$0.005 per additional Elastic IP address associated with a running instance per hour on a pro rata basis

Other Notes

Reference