Home > Net >  How to set static external IP on EC2 instance
How to set static external IP on EC2 instance

Time:08-20

I have an EC2 instance in private subnet and want to set fixed external IP address to allow access from server outside of AWS to EC2 instance. When I assign Elastic IP, my external address differs from this Elastic IP. I check my external IP with

curl https://icanhazip.com

How can I set fixed external IP for EC2 instance?

CodePudding user response:

Assumptions:

  • You have a private subnet with an Amazon EC2 instance
  • You have a public subnet with a NAT Gateway
  • The Route Table on the private subnet directs Internet-bound traffic to the NAT Gateway

When the private instance tries to access the Internet, requests will be sent via the NAT Gateway. The NAT Gateway will forward these requests to the Internet. The traffic will appear to come from the public IP address associated with the NAT Gateway.

Assigning a public IP address to an EC2 instance in a private subnet does nothing -- no traffic will ever 'use' that public IP address because the instance is unable to directly connect to the Internet Gateway.

  • Related