Home › Studies › AZ-104 › Virtual Networking › NSGs & ASGs

NSGs & ASGs

rules · default rules · priority · evaluation order · will traffic be allowed · ASGs · effective rules

By the tools4free.dev team · Last reviewed November 13, 2026

Practice questions for this topic →

How NSGs work

Default rules (in every NSG)

DirectionNamePrioritySourceDestinationAccess
InboundAllowVNetInBound65000VirtualNetworkVirtualNetworkAllow
InboundAllowAzureLoadBalancerInBound65001AzureLoadBalancer0.0.0.0/0Allow
InboundDenyAllInbound655000.0.0.0/00.0.0.0/0Deny
OutboundAllowVnetOutBound65000VirtualNetworkVirtualNetworkAllow
OutboundAllowInternetOutBound650010.0.0.0/0InternetAllow
OutboundDenyAllOutBound655000.0.0.0/00.0.0.0/0Deny

Evaluation order: will this traffic be allowed?

DirectionFirst NSGSecond NSG
InboundSubnet NSG (if any)NIC NSG (if any)
OutboundNIC NSG (if any)Subnet NSG (if any)

Worked example from Microsoft: the subnet NSG has no rule that allows port 80, and the NIC NSG allows port 80 from the Internet. Inbound port 80 is denied at the subnet NSG (DenyAllInbound). The NIC NSG never sees it. Both must allow.

No NSG and public IPs

Service tags, augmented rules and platform traffic

Application security groups (ASGs)

Learn example priorityRuleEffect
100Allow Internet to AsgWeb, TCP 80Web tier is reachable from the Internet
110Allow AsgLogic to AsgDb, TCP 1433Logic tier reaches the database
120Deny any to AsgDb, TCP 1433Blocks everything else. Needed because AllowVNetInBound would allow in-vnet traffic

Configure, associate and diagnose

Limits

ItemValue
Custom rule priority100-4096
Default rule priorities65000, 65001, 65500
NSGs per subscription per region5,000
Rules per NSG2,000
IPs and ranges per source or destination in a rule6,000
ASGs per subscription3,000
ASGs per NIC IP configuration20
ASGs in a single rule (source or destination)10
ASGs across all rules of one NSG100
IP configurations per ASG4,000

CLI and PowerShell

TaskAzure CLIPowerShell
Create NSGaz network nsg create -g myResourceGroup -n myNSGNew-AzNetworkSecurityGroup -Name myNSG -ResourceGroupName myResourceGroup -Location eastus
Create ruleaz network nsg rule create -g myRG --nsg-name myNSG -n RDP-rule --priority 300 --destination-port-ranges 3389 --protocol Tcp --description "Allow RDP"Add-AzNetworkSecurityRuleConfig ..., then Set-AzNetworkSecurityGroup
Update ruleaz network nsg rule update ... --priority 200Set-AzNetworkSecurityRuleConfig, then Set-AzNetworkSecurityGroup
Associate to a subnetaz network vnet subnet update -g myRG --vnet-name myVNet -n mySubnet --network-security-group myNSGSet-AzVirtualNetworkSubnetConfig -NetworkSecurityGroup, then Set-AzVirtualNetwork
Create ASGaz network asg create -g myRG -n myASG -l eastusNew-AzApplicationSecurityGroup
Effective security rulesaz network nic list-effective-nsg --name vm-nic -g test-rgGet-AzEffectiveNetworkSecurityGroup -NetworkInterfaceName vm-nic -ResourceGroupName test-rg

Exam Tips

Tick each tip once you can answer it without looking.

“Inbound rules have no Allow for port 80, and an internet request fails” → DenyAllInbound (65500) blocks it: add an Allow rule with a priority below 65500, such as 100. Trap: Editing DenyAllInbound. Default rules can't be edited.

“Allow rule at priority 200, Deny rule at priority 100, same traffic” → Deny wins: 100 is processed first. Trap: Allow, because it was created later.

“Two rules with the same priority and direction” → Not allowed. Trap: The first one created wins.

“Custom rule priority range” → 100-4096. Trap: 1-65535.

“Subnet NSG allows inbound 443; the NIC NSG has no allow for 443” → Denied at the NIC NSG by DenyAllInbound: both must allow. Trap: Allowed because the subnet NSG allows it.

“Outbound: which NSG is evaluated first” → The NIC NSG, then the subnet NSG. Trap: Subnet first. That's the inbound order.

“VM in a vnet connects to a VM in a peered vnet with default NSG rules” → Allowed: AllowVNetInBound and AllowVnetOutBound, because the VirtualNetwork tag includes peered vnets. Trap: Denied until a rule is added.

“Outbound to the internet from a VM with only default rules” → Allowed (AllowInternetOutBound, 65001). Trap: Denied by default.

“Delete the AllowVnetInBound default rule” → Not possible: override it with a lower-numbered Deny rule. Trap: Deleting it in the portal.

“Remove the allow-SSH rule while a session is open” → The existing session stays; new connections are blocked. Trap: The session dropping immediately.

“Allow the response to an allowed outbound web request” → No inbound rule needed: NSGs are stateful. Trap: Adding an inbound ephemeral port rule.

“Web and DB VMs in one subnet; only the app tier may reach the DB” → ASGs: Allow AsgLogic to AsgDb on 1433 (110), then Deny any to AsgDb on 1433 (120). Trap: Listing individual VM IPs.

“A NIC in vnet2 is added to an ASG whose first NIC is in vnet1” → Not allowed: all NICs in an ASG must be in the same vnet. Trap: Thinking peering makes it allowed.

“Delete an ASG that still has NICs” → Blocked: remove the NICs first. Trap: Cascade delete.

“See the combined subnet and NIC NSG rules for a VM” → Effective security rules on the NIC (the VM must be running). Trap: Opening the subnet NSG only.

“Rule must target a VM that has a public IP” → Use the VM's private IP: NSGs see the private IP for inbound traffic. Trap: The public IP.

“Role needed to associate an NSG with a subnet” → Microsoft.Network/networkSecurityGroups/join/action (in Network Contributor). Trap: Reader on the NSG.

“Block DNS or IMDS platform traffic with an NSG” → Use the AzurePlatformDNS or AzurePlatformIMDS service tags: these aren't filtered by default. Trap: Denying 168.63.129.16 as an IP.

“Send mail directly on port 25 from a pay-as-you-go VM” → Blocked: use an authenticated SMTP relay. Trap: Opening port 25 in the NSG.

“VM has a Standard public IP and no NSG on the subnet or NIC; inbound from the internet” → Blocked: Standard is closed until an NSG allows the traffic. Trap: Assuming no NSG means everything is open. That describes a Basic IP.

Sources

Checked against Microsoft Learn on November 13, 2026.

← Routing & UDRsAzure Bastion →