Azure NAT Gateway is a Network Address Translation Service. It provides outbound connectivity for one or more subnets of a virtual network. In this blog, we will understand
We have been making outbound connections in Azure even before the Azure NAT gateway was introduced. Even now, without a NAT gateway, we are making outbound connections. Then why Azure NAT Gateway? Do we really need to worry about this? The simple answer is - not unless you really make too many TCP connections in less time. Let’s understand this.
Let’s say we have Virtual Network with some basic subnet. Say this subnet is deployed with some VMs and scale set. We also have another subnet with an App Service is deployed where we host an API or website.
This Azure Virtual Network is a private network. Access to the resources inside the VNET is restricted. Now let’s talk about Out Bound connectivity. If the resources inside these virtual network need to talk to an API publicly available over the internet, sometimes the API needs to know what IP Address the request came from. But, the resources inside the VNET have a private IP address. This is needed to be translated to a public IP address before making outbound connectivity.
Each of this TCP connection need a port to be associated with it. But there are only 65K ports available to be used. This is a huge number of ports, but if we don’t design our application correctly ( for ex: if we don’t reuse the connections and make a lot of connections ) we can burn these connections easily.
Interestingly because of the way how Azure works today, you don’t really have ~65K ports available unless you have a static public IP address associated with a resource for ex for your VM. You actually get very less ports - It could be 1024 or even less than that. When there are no ports available to be used, these connections will fail. They don’t fail as refused connection, they simply time out. This is called SNAT Port Exhaustion.
CASE 1: If your VM has a static IP address, it has access to all ~65K ports. If you are making a huge number of TCP connections in small time and don’t reuse them, you might run into SNAT Port Exhaustion problem.
CASE 2: If your VM doesn’t have a static IP address, then it has fewer ports to access and if you are making more TCP connections in a short time without reusing them, you will most likely run into SNAT Port Exhaustion problem.
To solve this problem, Microsoft has introduced NAT Gateway to route all the traffic from a public static IP address.
So, what is Azure NAT Gateway? - NAT gateway provides outbound internet connectivity for one or more subnets of a virtual network with a dedicated public IP Address.
For detailed walkthrough of this demo, watch the Video
Now configure Azure function IP restrictions to allow traffic only from Azure NAT Gateway public IP address.
Now if we run the workflow it should work.
Legal Stuff