Project: Networking

Learn how to connect Azure resources.

We'll cover the following

Azure resources need connectivity to each other, so let’s set up the networking components to hook them all together.

vNet

All of the resources need to have network connectivity to each other. For this project, all resources will be in the same vNet and subnet.

Since you’re building a demo project, assigning everything in the same network is fine. But if you are building a multi-tiered application with a web frontend and database backend, you’re encouraged to place these “layers” in different vNets.

In the following code snippet, you can see the Azure CLI is creating a vNet called NoBSAzureLb-vNet with a /16 scope in the 10.0.0.0 network. This scope contains plenty of room to place the subnets we’ll be creating into.

export vNetName="$projectName-vNet"
az network vnet create -g $resourceGroupName --name $vNetName --address-prefixes '10.0.0.0/16'

Subnet

Next up, you must create one or more subnets in the vNet. Since this is a simple demo project, you’ll only be using a single subnet carving out 254 IP addresses from the vNet.

export subNetName="$projectName-Subnet"
az network vnet subnet create -g $resourceGroupName --address prefixes '10.0.0.0/24' --name $subNetName --vnet-name $vNetName

NSG and rules

And to round out the networking components, create an NSG and a single rule. The following code snippet is creating an NSG called NoBSAzureLb-Nsg and a single rule called NoBSAzure-Nsg-RuleHttp. This rule is allowing all inbound HTTP traffic to come in. For a production web application, you will probably also need to add an NSG rule for HTTPS (SSL) too.

export nsgName="$projectName-Nsg"
az network nsg create -g $resourceGroupName --name $nsgName

az network nsg rule create -g $resourceGroupName --nsg-name $nsgName --name "$nsgName-RuleHTTP" --protocol tcp --direction inbound --priority 1001 --source-address-prefix '*' --source-port-range '*' --destination-address-prefix '*' --destination-port-range 80 --access allow --priority 2000

Get hands-on with 1000+ tech skills courses.