1

I have an EC2 instance in a public subnet and I assigned an EIP to the instance and the IP address is Whitelisted to reach my company's network. The Instance must have a public IP address but I don't want to use EIP here. Whenever I restart the server the IP address is changing so I thought If I create a NAT Gateway and arrange the routeing table to use connect my company's network but when I do that I cannot reach the instance. NAT Gateway for the private network for but is there a way to set a static IP address to reach some places?

Default settings for the route table

enter image description here

Setting use NAT Gateway by default access did not work

enter image description here

Adding a new route for the company network did not work

enter image description here

Kenot Solutions
  • 377
  • 1
  • 4
  • 11
  • 2
    If you put the instance in a public subnet and assigned it an EIP, the IP address should not change between reboots. I suggest you change your question about getting that to work in the first place vs using a NAT Gateway where you don't need one. – Cargo23 Apr 15 '21 at 12:34
  • I don't want to use EIP so that is the problem. I know If I keep the EIP and it won't change with the restart. `The Instance must have a public IP address but I don't want to use EIP here` – Kenot Solutions Apr 15 '21 at 12:37
  • If you stop/start the EC2 instance it will lose its public IPv4 address. If you reboot it, it won't. – jarmod Apr 15 '21 at 13:18
  • yes but I could stop and start it so my question is even the public IP changes how can the instance goes a corporate network with the nat gateway or similar product. with the static IP address without using EIP. – Kenot Solutions Apr 15 '21 at 18:37

1 Answers1

0

To have a static IP address within AWS, you must use an Elastic IP. Even if you use a NAT Gateway, it consumes an EIP.

From the docs:

You must also specify an Elastic IP address to associate with the NAT gateway when you create it.

Cargo23
  • 3,064
  • 16
  • 25
  • I have to use EIP for NAT Gateway but I would use three EIP for 3 zones. Let's assume each zone has 50 instances then I have to use 150 EIP if I assign the IP address to the instances whereas with NAT I would use only 3 EIP. I can do it in private subnets my question is using a public subnet and assign a route to use NAT Gateway to reach a company network other traffic can use IGW. Please check the screenshots. – Kenot Solutions Apr 16 '21 at 08:09
  • As-is, your question is only about a single EC2 host. It might help if you explained the actual situation you are trying to address in your question. – Cargo23 Apr 19 '21 at 14:46