I got my app hosted on AWS, I use load balancer for it so I have to EC2 instances up. I need now to connect to some external service, but this service allows to connect from single IP.

I was thinking about setting up NAT gateway for my apps, but I don't know if I can setup one for all availability zones (I got my app configured in 3 AZ) of my app.

Do you have any idea how to make outbound requests from all my EC2 instances across all AZ/subnets to have single IP address?


If your app is deployed to a single VPC using the 3 Availability Zones then all you need to do is create a NAT Gateway on one of you public VNETs and then create a new Route table and add a route to send traffic through the new NAT Gateway. Finally associate the subnets that contain your app to the new route table.

A single NAT gateway can be used by any subnets in the same VPC regardless of the AZs that you have deployed the subnets to. When you create your NAT Gateway it will be given a single Elastic IP Address to use that will represent all the traffic being sent through the NAT Gateway.

| improve this answer | |
  • Thanks! I have successfully (I hope) configured my NAT. Is there a way to connect via ssh to one of EC2 instances behind NAT? – Blejwi Mar 31 '17 at 11:20
  • No, NAT gateways don't allow a connection to be initiated from the outside, the connection has to be initiated from the inside to the outside. – Michael Brown Mar 31 '17 at 11:47
  • If you need to be able to ssh to a server for maintenance, and don't have any VPN or Direct connect set up to allow access to your private subnets, there are a few approaches. The normal way, is to set up a 'bounce' box in the public subnet, which you ssh to, and then ssh to the instance. I've also heard people creating a temporary ELB configured to forward ssh, and adding a single instance to it. – KHobbits Mar 31 '17 at 13:50
  • A "bounce box" or "jump box" is more formally called a "bastion host", you can find instructions how to set one up here: aws.amazon.com/about-aws/whats-new/2016/09/… – Tim Mar 31 '17 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.