Setup Dual Public IP for AWS EC2
- Setup Dual Public IP in AWS Web Console
- Config EC2 instance to recognize the extra IP
- Pricing
- Other Notes
- Reference
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.
-
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.
-
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.
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
- The number of network interfaces and private addresses that you can specify for an instance is limited, depending on the instance type. See IP Addresses Per Network Interface Per Instance Type.