0
0
Azurecloud~10 mins

Network Security Groups (NSG) in Azure - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Network Security Groups (NSG)
Create NSG
Define Security Rules
Associate NSG to Subnet or NIC
Traffic Arrives
Check Rules in Priority Order
Allow or Deny Traffic
Traffic Allowed or Blocked
This flow shows how an NSG is created, rules are defined, associated to network resources, and how incoming traffic is checked against these rules to allow or block it.
Execution Sample
Azure
Create NSG "web-nsg"
Add rule: Allow TCP 80 inbound priority 100
Add rule: Deny all inbound priority 200
Associate NSG to subnet "web-subnet"
This example creates an NSG with two rules and associates it to a subnet to control inbound traffic.
Process Table
StepActionRule CheckedTraffic PortRule ResultTraffic Outcome
1Create NSG 'web-nsg'N/AN/AN/ANSG created
2Add rule: Allow TCP 80 inbound priority 100Allow TCP 80 inboundN/ARule addedN/A
3Add rule: Deny all inbound priority 200Deny all inboundN/ARule addedN/A
4Associate NSG to subnet 'web-subnet'N/AN/AN/ANSG associated
5Inbound traffic arrives on port 80Allow TCP 80 inbound80MatchAllowed
6Inbound traffic arrives on port 22Allow TCP 80 inbound22No matchCheck next rule
7Inbound traffic arrives on port 22Deny all inbound22MatchDenied
8Inbound traffic arrives on port 443Allow TCP 80 inbound443No matchCheck next rule
9Inbound traffic arrives on port 443Deny all inbound443MatchDenied
10Inbound traffic arrives on port 80Allow TCP 80 inbound80MatchAllowed
💡 Traffic is allowed or denied based on the first matching rule in priority order.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5-10
NSG RulesNone[Allow TCP 80 inbound, priority 100][Allow TCP 80 inbound, priority 100; Deny all inbound, priority 200][Rules associated to subnet][Rules applied to incoming traffic]
Traffic PortN/AN/AN/AN/A80, 22, 443, 80 (varies per step)
Traffic OutcomeN/AN/AN/AN/AAllowed or Denied based on rules
Key Moments - 3 Insights
Why does traffic on port 22 get denied even though there is no explicit deny rule for port 22?
Because the deny all inbound rule with lower priority (higher number) matches all ports not allowed by earlier rules, so port 22 traffic is denied as shown in steps 6 and 7.
What happens if multiple rules match the same traffic?
The rule with the highest priority (lowest number) is applied first, so traffic is allowed or denied based on the first matching rule, as seen in step 5 where port 80 is allowed by the first rule.
Why do we associate the NSG to a subnet or NIC?
Associating the NSG to a subnet or NIC applies the rules to all traffic entering or leaving that resource, controlling network access as shown in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the traffic outcome for inbound traffic on port 443 at step 9?
AAllowed
BNo decision yet
CDenied
DRule not found
💡 Hint
Check the 'Traffic Outcome' column at step 9 in the execution table.
At which step does the NSG get associated to the subnet?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look for the action mentioning 'Associate NSG to subnet' in the execution table.
If the deny all inbound rule was removed, what would happen to traffic on port 22?
AIt would be allowed by default
BIt would be denied by default
CIt would match the allow TCP 80 rule
DIt would cause an error
💡 Hint
Refer to the key moment explaining the deny all inbound rule effect on unmatched ports.
Concept Snapshot
Network Security Groups (NSG) control network traffic by applying rules.
Rules have priorities; lower numbers run first.
Traffic is allowed or denied based on the first matching rule.
NSGs are associated with subnets or network interfaces.
Default deny applies if no rule matches.
Use NSGs to protect Azure resources from unwanted traffic.
Full Transcript
Network Security Groups (NSG) are used in Azure to control network traffic to and from resources. First, you create an NSG and add security rules with priorities. Then, you associate the NSG to a subnet or network interface. When traffic arrives, Azure checks the rules in priority order. The first rule that matches the traffic decides if it is allowed or denied. For example, if there is a rule allowing TCP traffic on port 80 with priority 100, and a deny all inbound rule with priority 200, traffic on port 80 is allowed, but traffic on other ports like 22 or 443 is denied. This process helps secure your network by controlling access. If no rule matches, traffic is denied by default. Associating NSGs to subnets or NICs applies these rules to all traffic entering or leaving those resources.