Grouping VMs with Application Security Groups
This lesson explains how application security groups let NSG rules refer to VMs by role.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how ASGs are used in NSG rules.
- Identify the limitations of ASGs.
- Choose between IP addresses and ASGs in rules.
How ASGs work
An application security group is a resource that acts as a label. Network interfaces of VMs are added to one or more ASGs on the VM's Networking page (Application security groups) or with az network nic ip-config update --application-security-groups. NSG rules then use ASGs as the source or destination, for example "allow asg-web to asg-sql on TCP 1433". When a VM is added to or removed from an ASG, the rules apply to it automatically, without editing IP addresses.
ASGs simplify micro-segmentation within a subnet or across subnets: web and database VMs can share a subnet while rules still distinguish them. A NIC can belong to several ASGs, and a rule can reference several ASGs.
The following diagram shows application security groups that segment web and SQL VMs in one subnet, and the NSG rules that use them.

Using application security groups
Rules and limitations
All network interfaces in an ASG must be in the same virtual network as the first NIC added to it, and a rule that uses ASGs as both source and destination requires all of them to be in the same VNet. ASGs cannot be used across peered VNets. They are free, and they work together with service tags and IP addresses in the same NSG.
ASG rules
Segmenting tiers
A subnet contains 6 web VMs and 2 SQL Server VMs. Only web VMs may connect to SQL Server on TCP 1433, the web VMs must accept HTTPS from the internet, and new web VMs will be added often. The solution must minimize rule maintenance. What should you configure?
Create ASGs asg-web and asg-sql, add each VM's NIC to the right ASG, and add NSG rules on the subnet: allow Internet to asg-web on TCP 443; allow asg-web to asg-sql on TCP 1433; and deny VirtualNetwork to asg-sql on 1433 with a higher priority number than the allow rule, so that other VMs are blocked despite the default AllowVNetInBound rule. New web VMs only need their NIC added to asg-web.
Can NICs from two different VNets be members of the same application security group?
Show answer
No. All NICs in an ASG must be in the same virtual network.
Exam Tips
Remember for the exam
- ASGs group NICs by role so rules do not depend on IP addresses.
- All NICs in an ASG must be in the same VNet.
- Add a deny rule to override AllowVNetInBound for tiers that must be isolated.
- A NIC can belong to several ASGs.