Search code examples
azurevpnazure-virtual-networkazure-vpn

Azure gateway with a virtual network


I've got multiple questions on the setup of a gateway and VM, so here is what I have actually.

I've got an Application Gateway, and two VM Ubuntu, everything hosted on Azure. They are all on the same Virtual Network. Both VM have only a private IP (10.1.0.4 and 10.1.0.5) and the Gateway have a private IP (10.1.1.4) and a public IP. Because only the Gateway have a public IP, I guess that everything have to go through it, and this is what I want to.

The goals I try to achieve :

  • Make a load balancer on the port 1680, redirected to port 1680.

  • To redirect the SSH of each VM to connect specifically to one because at the moment, they have no public IP. Is it possible to do this with a path based rule ? Like www.example.com/VM1 to connect by SSH to the first VM ? If no, what can be used to differentiate the SSH connection of the VM1 and of the VM2 ?

  • To redirect the port 80 of the gateway to the port 8080 of a specific VM. As my previous example, www.example.com/adminPanelVM1 to connect to the first VM on port 80 (redirected to port 8080 on the VM)

I already managed to create the redirection of the port 1680 of the Gateway with an HTTP Parameter, a Listener and a Rule.


Solution

  • Azure Application Gateway

    The Azure Application Gateway operates at the layer 7 in the OSI model on the HTTP/HTTPS/WebSocket protocols, because of that any other protocol (like SSH), is not possible to route.

    You got a few options tho.

    You can use a Network Security Group, or NSG, for access control to your virtual machines. In the NSG you define where the traffic can come from that is allowed access to the VMs.

    A NSG behaves like a access-control-list filtering traffic based on source and destination information and evaluating rules in order of priority. See this page for more information about NSGs.

    Another option is to use a load balancer.

    Azure Load Balancer

    If you need to do port mapping, like you describe in your question, then a simple load balancer might be a better solution for you. An Azure Load Balancer works at a lower level in the in the OSI model, namely layer 4 (transport layer), handling TCP/UDP traffic.

    So, if you are using a load balancer, then you can set up NAT rules to forward your traffic to specific machines, in other words, if you want to do:

    • LB port 1234 redirects to VM1 port 22 and
    • LB port 4312 redirects to VM2 port 22

    you can do that using PowerShell as described in the Creating a public load balancer in Resource Manager by using PowerShell article.

    There are quite a few steps but it walks you through the whole process of creating NAT rules, NICs and associated virtual machines.

    Azure Application Gateway vs Azure Load Balancer?

    These two cervices are distinctly different services and are trying to solve different problem, although those problems might look similar :)

    The primary uses of an Application Gateway are:

    • SSL termination
    • cookie-based session affinity
    • round robin for load balancing traffic

    Where as the Azure Load Balancer service works as the TCP/UDP level and support e.g. port mapping.

    Cost wise, the load balancer service is free while the application gateway is billed per hour.

    There are many great articles on this topic, when to pick which service. See for example the links for more details