Search code examples
amazon-web-servicesnetworkingamazon-ec2amazon-vpcelastic-ip

Can a the same AWS ElasticIP be shared by a NAT gateway and an EC2 instance in a public subnet?


As described in the aws VPC scenario 2 page I have a VPC with 2 subnets defined - one private and one public. The private subnet uses a NAT gateway for the outbound traffic (the NAT gateway lives in the public subnet). The public subnet uses an internet gateway for inbound and outbound.

The usage of the NAT gateway requires an ElasticIP to be registered and associated with that NAT. Now, I need a public IP for the EC2 instance I have in the public subnet, that remains static even after restarting the instance, where outside traffic can come into. Do I need to register another ElasticIP for that purpose, or can I reuse the same ElasticIP that I already created for the NAT Gateway?


Solution

  • An Elastic IP address can only be registered to one ENI at a single time. When you create it a mapping is formed to resolve the elastic IP address to a single private address on an ENI (be that a NAT Gateway or an EC2 host).

    When you associate an Elastic IP address with an instance, it is also associated with the instance's primary network interface. When you associate an Elastic IP address with a network interface that is attached to an instance, it is also associated with the instance.

    You will need to create a new one for your EC2 host, by default you can use 5 elastic IP addresses in a region, if you need more than this you would need to contact Amazon to increase your accounts quota.

    For more information take a look at the Elastic IP addresses page.