DEV Community

Cover image for How to Create and Configure Network Security Groups in Azure"
SUBAIR NURUDEEN ADEWALE
SUBAIR NURUDEEN ADEWALE

Posted on

How to Create and Configure Network Security Groups in Azure"

Introduction

In modern cloud environments, controlling and securing network traffic is critical to protecting workloads and ensuring smooth application performance. An Azure Network Security Group (NSG) acts as a virtual firewall that filters inbound and outbound traffic for Azure resources. Combined with Application Security Groups (ASGs), administrators can simplify the management of access policies by grouping similar servers and applying rules consistently.

Skilling tasks

  • Create a network security group.
  • Create network security group rules.
  • Associate a network security group to a subnet.
  • Create and use application security groups in network security group rules.

  • Create a Network Security Group (NSG)

  • Provision an NSG that can be associated with the backend subnet of the app-vnet.

  • Create Network Security Group Rules

  • Define inbound and outbound rules to control traffic flow between the frontend and backend resources.

  • Associate a Network Security Group to a Subnet

  • Link the NSG to the backend subnet in the app-vnet to secure database server access.

  • Create and Use Application Security Groups (ASGs)

  • Create an ASG (app-frontend-asg) for web servers in the frontend subnet.

  • Associate the ASG with VM1’s network interface.

  • Use the ASG in NSG rules to simplify traffic management.

  • Deploy and Test Virtual Machines

  • Deploy VM1 in the frontend subnet and VM2 in the backend subnet using the provided ARM template.

  • Verify traffic control using the configured NSG and ASG rules.

Step 1 Create the network infrastructure for the exercise

  • Use the icon (top right) to launch a Cloud Shell session.

  • Use these commands to deploy the virtual machines required for this exercise. copy and paste the command on the cloudshell.

New-AzResourceGroupDeployment -ResourceGroupName RG1 -TemplateUri https://raw.githubusercontent.com/MicrosoftLearning/Configure-secure-access-to-workloads-with-Azure-virtual-networking-services/main/Instructions/Labs/azuredeploy.json

  • In the portal search for and select virtual machines.

  • Verify both vm1 and vm2 are Running.

Step 2 Create Application Security Group

Application security groups (ASGs) let you group together servers with similar functions. For example, all the web servers hosting your application.

  • In the portal, search for and select Application security groups.

  • Select + Create

  • Configure the application security group.

  • Property Value

  • Subscription Select your subscription

  • Resource group RG1

  • Name app-frontend-asg

  • Region East US

  • Select Review + create

  • Then select Create.

  • The application security group as been created successfully

Step 3 Associate the application security group to the network interface of the VM

  • In the Azure portal, search and select Virtual Machine.

  • Select VM1.

  • In the Networking blade, select Application security groups and then select Add application security groups.

  • Select the app-frontend-asg and then select Add.

  • Application security group as been added to VM1

Step 4 Create and Associate the Network Security Group

Network security groups (NSGs) secure network traffic in a virtual network.

  • In the portal search for and select Network security group.

  • Select + Create.

  • Configure the network security group.

  • Property Value

  • Subscription Select your subscription

  • Resource group RG1

  • Name app-vnet-nsg

  • Region East US

  • Select Review + create

  • Then select Create.

  • The network security group as been created succesfuly

Step 5 Associate the NSG with the app-vnet backend subnet.

NSGs can be associated with subnets and/or individual network interfaces attached to Azure virtual machines.

  • Select Go to resource or navigate to the app-vnet-nsg resource.

  • In the Settings blade select Subnets.
  • Select + Associate
  • Select app-vnet (RG1) and then the Backend subnet. Select OK.

  • Backend submit as been associated to the network security group

Step 6 Create Network Security Group rules

An NSG use security rules to filter inbound and outbound network traffic.

  • In the search box at the top of the portal, enter Network security groups. Select Network security groups in the search results.

  • Select app-vnet-nsg from the list of network security groups.

  • In the Settings blade, select Inbound security rules.
  • Select + Add and configure an inbound security rule.

Source: Any
Source port ranges: *
Destination: Application Security group
Destination application security group app-frontend-asg
Service SSH
Action: Allow
Priority: 100
Name: AllowSSH

  • Network security group rule as been created

Conclusion

By completing this exercise, you have:

Created and configured a Network Security Group (NSG) to control network traffic.
Built and associated an Application Security Group (ASG) with frontend virtual machines for simplified management.
Deployed virtual machines across frontend and backend subnets to test secure communication.
Applied custom inbound rules in the NSG to allow secure SSH access from the frontend to the backend.

This project demonstrates how NSGs and ASGs work together to enforce granular network security in Azure. You can now confidently design policies that secure workloads, isolate subnet traffic, and simplify access management across cloud resources.

Top comments (0)