Home › Studies › AZ-700 › Network Security › Network Security Groups

Network Security Groups

NSG rules and priority · default rules · subnet and NIC evaluation order · ASGs · virtual network flow logs · IP flow verify · Bastion NSG rules · security admin rules

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

Practice questions for this topic →

Security rules

PropertyWhat to know
NameUnique within the NSG; up to 80 characters.
Priority100 to 4096. Lower number = higher priority. Once traffic matches a rule, processing stops. You can't create two rules with the same priority and direction.
Source / destinationAny, an IP address, a CIDR block, a service tag or an application security group. To name an Azure VM, use its private IP address.
ProtocolTCP, UDP, ICMP, ESP, AH or Any. ESP and AH aren't available in the portal; use an ARM template.
DirectionInbound or outbound.
Port rangeOne port, a range, or a comma-separated mix such as 80, 10000-10005.
ActionAllow or Deny.

Permissions: to manage NSGs, rules and application security groups you need the Network Contributor role (or a custom role). Associating an NSG to a subnet or NIC uses the Microsoft.Network/networkSecurityGroups/join/action permission.

Default rules and evaluation order

Azure creates six default rules in every NSG. They have the lowest priority (highest numbers), so your rules are always processed first. You can't remove them, but a rule with a higher priority overrides them.

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

Subnet NSG and NIC NSG

DirectionFirstSecond
InboundNSG on the subnetNSG on the network interface
OutboundNSG on the network interfaceNSG on the subnet

Check what applies

Application security groups

An application security group (ASG) lets you group VMs and write rules against the group instead of IP addresses. Security follows the application's structure and you don't maintain address lists.

Example rule set (three tiers behind one subnet NSG)

PriorityRuleSourceDestinationPortAction
100Allow-HTTP-Inbound-InternetInternetAsgWeb80 TCPAllow
110Allow-Database-BusinessLogicAsgLogicAsgDb1433 TCPAllow
120Deny-Database-All*AsgDb1433 AnyDeny

Why rule 120 is needed: AllowVNetInBound allows all traffic inside the virtual network. Rule 110 has a higher priority than rule 120, so AsgLogic reaches AsgDb and everything else is denied. No rule is needed to block the internet from AsgLogic or AsgDb, because DenyAllInbound already does.

Virtual network flow logs

Virtual network flow logs are a Network Watcher feature. They log IP traffic through a virtual network and write it to Azure Storage. They overcome some limitations of NSG flow logs, which are retiring.

SettingRequirement
TargetCreate a flow log for a virtual network, a subnet or a network interface.
Resource providerMicrosoft.Insights must be registered.
Storage accountSame region as the virtual network; same subscription or a subscription in the same Microsoft Entra tenant; standard performance (premium isn't supported).
RetentionSet in days; 0 keeps data until you delete it. Retention days need a Standard general-purpose v2 account.
Traffic analyticsOptional. Processing interval is every 1 hour (default) or every 10 minutes; needs a Log Analytics workspace.
Customer-managed keysIf you change or rotate the keys on the storage account, flow logs stop working. Disable and re-enable them.

Read a flow log

Tuple fieldValues
Flow directionI inbound, O outbound
Flow stateB begin, C continuing, E end, D deny
Flow encryptionX encrypted; NX unencrypted (the default); other NX_ codes explain why encryption wasn't applied
Packets and bytesFor C and E records, the counts are aggregates since the previous record of the flow. Add the records to get the conversation total.

Sample from the page: 1663145998065,101.33.218.153,10.0.0.6,55188,22,6,I,D,NX,0,0,0,0 reads as inbound (I), denied (D), unencrypted, from 101.33.218.153 port 55188 to 10.0.0.6 port 22, protocol 6, with zero packets and bytes.

Retirement: NSG flow logs retire on September 30, 2027 and no longer support new NSG flow log creation. After that date Azure deletes existing NSG flow log resources and drops traffic analytics for them; the records already in storage are kept under their retention policy. Migrate to virtual network flow logs.

NSG rules for Azure Bastion

Azure Bastion supports NSGs on the AzureBastionSubnet and on the target VM subnets. If you apply an NSG to the Bastion subnet you must create every required rule below. Leaving one out blocks platform updates and can block VM connectivity.

RuleDirectionSourceDestinationPortPurpose
AllowHttpsInboundInboundInternet*443Users reach Bastion over HTTPS. Source can be Internet or specific public IPs.
AllowGatewayManagerInboundInboundGatewayManager*443Control plane talks to the Bastion host.
AllowBastionHostCommunicationInboundVirtualNetworkVirtualNetwork8080, 5701Bastion components talk to each other.
AllowAzureLoadBalancerInboundInboundAzureLoadBalancer*443Load balancer health probes.
AllowSshRdpOutboundOutbound*VirtualNetwork22, 3389Bastion reaches the target VMs over private IP.
AllowAzureCloudOutboundOutbound*AzureCloud443Diagnostics and metering logs.
AllowBastionCommunicationOutboundVirtualNetworkVirtualNetwork8080, 5701Bastion components talk to each other.
AllowHttpOutboundOutbound*Internet80Session validation, shareable link, certificate validation.

Security admin rules (Azure Virtual Network Manager)

Security admin rules are global rules that a central team deploys with Azure Virtual Network Manager. They apply to virtual networks in a network group and are evaluated before NSG rules.

ActionWhat happens next
AllowEvaluated first; then traffic continues to NSG rules, which can still allow or deny it.
Always allowEvaluation stops. Traffic goes to the resource and NSG rules can't block it.
DenyEvaluation stops. Traffic is blocked and not delivered to the destination.

CLI and PowerShell

TaskAzure CLIPowerShell
Create an NSGaz network nsg create --resource-group myResourceGroup --name myNSGNew-AzNetworkSecurityGroup @NSGParams
Add an NSG ruleaz network nsg rule create --resource-group myResourceGroup --nsg-name myNSG --name RDP-rule --priority 300 --destination-address-prefixes '*' --destination-port-ranges 3389 --protocol Tcp --description "Allow RDP"Add-AzNetworkSecurityRuleConfig -NetworkSecurityGroup $networkSecurityGroup @RuleParams
Associate an NSG with a subnetaz network vnet subnet update --resource-group myResourceGroup --vnet-name myVNet --name mySubnet --network-security-group myNSGSet-AzVirtualNetworkSubnetConfig -VirtualNetwork $virtualNetwork @SubnetParams
Associate an NSG with a network interfaceaz network nic update --name myNIC --resource-group myResourceGroup --network-security-group myNSG$nic.NetworkSecurityGroup = $nsg; $nic | Set-AzNetworkInterface
Create an application security groupaz network asg create --resource-group myResourceGroup --name myASG --location eastusNew-AzApplicationSecurityGroup @ASGParams
Add a NIC to an application security groupaz network nic ip-config update --name ipv4config --nic-name myNIC --resource-group myResourceGroup --application-security-groups myASG$nic | Set-AzNetworkInterfaceIpConfig @IP; $nic | Set-AzNetworkInterface
View a NIC's effective security rulesaz network nic list-effective-nsg --name myNIC --resource-group myResourceGroupGet-AzEffectiveNetworkSecurityGroup -NetworkInterfaceName myNIC -ResourceGroupName myResourceGroup
Register the Insights provider (needed for flow logs)az provider register --namespace Microsoft.InsightsRegister-AzResourceProvider -ProviderNamespace Microsoft.Insights
Create a virtual network flow logaz network watcher flow-log create --location 'eastus' --resource-group 'myResourceGroup' --name 'myVNetFlowLog' --vnet 'myVNet' --storage-account 'myStorageAccount'New-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id -FormatVersion 2

Exam Tips

Tick each tip once you can answer it without looking.

“Which NSG is evaluated first for inbound traffic when a subnet NSG and a NIC NSG both exist?” → The subnet NSG, then the NIC NSG. Trap: Outbound is the reverse (NIC first). Both must allow the traffic.

“Which NSG is evaluated first for outbound traffic when both levels have an NSG?” → The NIC NSG, then the subnet NSG. Trap: Don't reuse the inbound order; it is reversed.

“Two rules at priorities 200 (Deny TCP 443) and 300 (Allow TCP 443) both match” → Priority 200 wins; the Deny applies and processing stops. Trap: A higher number is a lower priority, so the Allow at 300 is never reached.

“Add a rule with the same priority and direction as an existing rule” → Not possible; priority must be unique per direction in an NSG. Trap: Two rules with the same priority and direction can conflict.

“Default rules block inbound internet traffic to a VM; what do you create to allow it?” → A custom allow rule (priority 100 to 4096) that matches the traffic. Trap: You can't delete defaults, but you can override them with higher-priority rules.

“Allow web VMs to reach database VMs without IP lists, as the VMs scale” → Application security groups as source and destination. Trap: All NICs in a rule's ASGs must be in the same virtual network; an ASG can't span VNets.

“Put NICs from two virtual networks in one ASG” → Not possible. Trap: Every NIC in an ASG must be in the VNet of the first NIC added.

“You remove the rule that allowed an active SSH session” → The open session stays up; new connections are blocked. Trap: Rule changes only affect new connections.

“Replace NSG flow logs” → Virtual network flow logs (enable at the virtual network, subnet or NIC). Trap: NSG flow logs retire September 30, 2027 and can't be newly created.

“Flow log storage account is in another region than the virtual network” → Not allowed; the account must be in the same region, with standard performance. Trap: Premium storage accounts aren't supported.

“A flow log tuple shows I,D” → Inbound flow that was denied. Trap: D is Deny; O would be outbound.

“Check which rule blocks traffic to a VM” → IP flow verify (Network Watcher). Trap: It tests TCP and UDP only; use NSG diagnostics for ICMP or scale sets.

“Bastion NSG on AzureBastionSubnet: which inbound rule carries the control plane?” → 443 inbound from the GatewayManager service tag. Trap: Missing rules block platform updates; 22 and 3389 aren't needed inbound on this subnet.

“Target VM subnet NSG must let Bastion connect” → Inbound 22 and 3389 from the AzureBastionSubnet range. Trap: Don't open them to the internet; the VM needs no public IP.

“A central team must block RDP on every VNet, even where app teams have allowed it in NSGs” → A Virtual Network Manager security admin rule with the Deny action. Trap: Security admin rules are evaluated before NSG rules, and a Deny ends evaluation. An Allow action would pass on to the NSGs.

“Security admin rule action that overrides a conflicting NSG deny” → Always allow. Trap: Allow continues to NSG rules, which can still deny it.

“Deploy a second security admin configuration to the same region” → Not possible; add another rule collection to the existing configuration. Trap: One security admin configuration per region.

Sources

Checked against Microsoft Learn on November 13, 2026.

← Network Security overviewAzure Firewall & Firewall Manager →