0

There is an instance in Amazon EC2 VPC with private IP address only, 192.168.1.100. VPC uses Internet Gateway to get connection to the public network. I've found my IP address using 'curl -s checkip.dyndns.org', let it be 1.2.3.4

Now I need to communicate with 3-rd party team, so that they allow incoming requests from my 1.2.3.4 address on their firewall. I don't want to wake up some day and find out that server can't communicate with 3-rd party API because my ip changed for them and firewall blocks everything from their side.

My main question is: Does public IP address of my instance stay the same for the 3-rd party firewall in case Internet Gateway for VPC doesn't change? Or there is no way to maintain my public IP and the only option is to use either Elastic IP address or NAT Gateway service?

2 Answers 2

1

If you do not allocate an EIP for your instance, the public address assigned to the instance will change if the instance is stopped then restarted.

There is no charge for EIP allocations as long as what you allocate is actively in use on a running instance (see: https://aws.amazon.com/premiumsupport/knowledge-center/elastic-ip-charges/)

I've seen EC2 instances with uptimes exceeding a year. I have also been in the position of having long-running instances being stopped (not by me)--I imagine these were due to system (hypervisor) failure or the rack the hypervisor was part of getting decommissioned.

The take-a-way: If you don't allocate an EIP,

  • the public address will stay the same until/unless the instance is stopped
  • there is no way to get that address back

If you do allocate an EIP:

  • No charge unless the EIP not attached to a running instance

    • within us-west-2, an allocated, unused EIP will cost you 12 cents per day
  • an allocated EIP is attached to your Account/VPC until you release it

  • when you release an EIP, it is gone. The likelihood of you getting it back is tiny
2

Short answer: assign an ElasticIP address. It's free.

Long answer: A better way to find your public IP is using the instance metadata. This gives you your public or elastic IP.

curl http://169.254.169.254/latest/meta-data/public-ipv4
(response) 1.2.3.4

Your automatically assigned public IP will change if you stop and start your instance, but won't change if you reboot your instance operating system. However the auto assigned IPs aren't for long term use.

Assign an ElasticIP to your instance. It won't change. The only caveat is "You will be charged "$0.005 per Elastic IP address not associated with a running instance per hour on a pro rata basis". If you request an ElasticIP then assign it to your instance straight away there will be no cost. This EIP replaces your automatically assigned public IP address.

Internet Gateway is irrelevant, it's a logical concept that allows Internet communication. If you were using a NAT to allow instances in a private subnet to talk to the Internet then you'd have to use it's IP, but it doesn't sound like you're doing that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .