Fix Azure Virtual Network Asg Errors
When working with Azure Virtual Network, you may encounter a configuration error that prevents your deployment from working. This guide explains the most common mistake with asg and shows the exact fix.
A Common Mistake
Not using Application Security Groups (ASGs) to organize NSG rules, resulting in complex NSG rules with hardcoded IP addresses.
The incorrect command:
az network nsg rule create --name allow-web-to-db --nsg-name my-nsg --resource-group my-rg --priority 200 --direction Inbound --access Allow --protocol Tcp --source-address-prefixes 10.100.1.4,10.100.1.5,10.100.1.6 --source-port-ranges * --destination-address-prefixes 10.100.2.4 --destination-port-ranges 3306
Error output:
NSG rule created with hardcoded IPs.
When web VMs scale out, new VMs get different IPs. The NSG rule does not cover new VMs. Database connections fail. Every scale event requires NSG updates. Hardcoded IPs are a maintenance nightmare.
The Correct Approach
The right way to configure asg in Azure Virtual Network:
az network asg create --name web-asg --resource-group my-rg
az network asg create --name db-asg --resource-group my-rg
az network nsg rule create --name allow-web-to-db --nsg-name my-nsg --resource-group my-rg --priority 200 --direction Inbound --access Allow --protocol Tcp --source-asgs web-asg --source-port-ranges * --destination-asgs db-asg --destination-port-ranges 3306
az network nic update --name web-vm-nic --resource-group my-rg --application-security-groups web-asg
Successful result:
NSG rule created with ASGs.
When web VMs scale out, new NICs are added to web-asg. The NSG rule automatically applies. No manual IP updates needed. ASGs provide dynamic, scalable network security.
How to Prevent This
Use ASGs to group VMs by function (web, app, db). Reference ASGs in NSG rules instead of IP addresses. ASGs work across NICs, not subnets. Combine ASGs with NSG for flexible security. ASGs are free and available in all regions.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Secure your cloud with DodaTech.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro