amazon-web-servicesamazon-vpcnat

How to use NAT Gateway for only outbound traffic


I need a static ip to hit an URL. For that I am planning to put NAT Gateway with static IP in front of instances for outbound traffic.

So the question here is how to use IGW for input traffic and NAT for outbound traffic.


Solution

  • You don't need to do anything. That is exactly how it works. Almost.

    Your configuration should be:

    Then, anything traffic that comes out of instances in a Private Subnet will be routed to the NAT Gateway, which forwards the traffic to the Internet. It will come from the Elastic IP address. Return traffic will flow back through the NAT Gateway to the instance in the Private Subnet.

    Incoming traffic to the VPC (that is not responding to the NAT Gateway) will not be able to reach the instances in the Private Subnet because they are not directly connected to the Internet. This is intentional.

    Please note that the Internet Gateway attaches the VPC to the Internet and is used for both inbound and outbound traffic. Just think of it as plugging a cable into the Internet.