Bird
Raised Fist0
Azurecloud~10 mins

NSG rules (inbound, outbound) in Azure - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - NSG rules (inbound, outbound)
Start: Packet arrives
↓
Check Inbound NSG Rules
↓
Match Rule?
No→Drop Packet
Yes↓
Allow or Deny?
↓
If Allow -> Packet forwarded to VM
↓
Packet leaves VM
↓
Check Outbound NSG Rules
↓
Match Rule?
No→Drop Packet
Yes↓
Allow or Deny?
↓
If Allow -> Packet sent out
When a network packet arrives, inbound NSG rules are checked first to allow or deny it. If allowed, the packet reaches the VM. When leaving, outbound NSG rules are checked similarly.
Execution Sample
Azure
inbound_rule = {"priority": 100, "direction": "Inbound", "access": "Allow", "protocol": "TCP", "port": 80}
outbound_rule = {"priority": 100, "direction": "Outbound", "access": "Deny", "protocol": "TCP", "port": 22}
packet = {"direction": "Inbound", "protocol": "TCP", "port": 80}
result = check_nsg_rules(packet, [inbound_rule], [outbound_rule])
This code checks if an inbound TCP packet on port 80 is allowed by NSG rules.
Process Table
StepPacket DirectionRule Direction CheckedRule MatchedAccess ActionPacket Status
1InboundInboundYes (priority 100, TCP port 80)AllowPacket allowed to VM
2OutboundOutboundNo (no matching rule for outbound TCP port 80)Default DenyPacket dropped
3End---Packet blocked outbound due to no allow rule
💡 Outbound packet dropped because no outbound rule allowed TCP port 80; default deny applies.
Status Tracker
VariableStartAfter Step 1After Step 2Final
packet_statusPendingAllowed inboundDropped outboundDropped outbound
rule_checkedNoneInbound rule matchedNo outbound rule matchedNo outbound rule matched
Key Moments - 2 Insights
Why does the packet get dropped on outbound even though inbound was allowed?
Because NSG rules are checked separately for inbound and outbound directions. The inbound rule allowed the packet in, but no outbound rule allowed it out, so the default deny applies as shown in execution_table row 2.
What happens if no NSG rule matches the packet direction and port?
The packet is denied by default. This is shown in execution_table row 2 where no outbound rule matched, so the packet was dropped.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the packet status after step 1?
APacket allowed to VM
BPacket dropped
CPacket forwarded outbound
DPacket ignored
💡 Hint
Check the 'Packet Status' column in execution_table row 1.
At which step does the packet get dropped due to no matching outbound rule?
AStep 1
BStep 2
CStep 3
DNo drop occurs
💡 Hint
Look at execution_table row 2 where outbound check fails.
If the outbound rule allowed TCP port 80, how would the packet status change after step 2?
APacket would still be dropped
BPacket would be allowed outbound
CPacket would be dropped inbound
DPacket status would be unknown
💡 Hint
Refer to variable_tracker and execution_table showing how access action affects packet status.
Concept Snapshot
NSG rules control network traffic by direction: inbound rules check packets entering a VM, outbound rules check packets leaving.
Each rule has priority, direction, protocol, port, and access (Allow or Deny).
Packets are checked against rules in priority order; first match decides allow or deny.
If no rule matches, default deny applies.
Inbound and outbound checks are separate steps.
This protects VMs by filtering traffic both ways.
Full Transcript
Network Security Group (NSG) rules in Azure control traffic flow to and from virtual machines. When a packet arrives, inbound NSG rules are checked first. If a rule matches the packet's direction, protocol, and port, its access setting (Allow or Deny) determines if the packet proceeds. If allowed, the packet reaches the VM. When the VM sends a packet out, outbound NSG rules are checked similarly. If no rule matches, the packet is denied by default. This two-step check ensures security both entering and leaving the VM. The example shows an inbound TCP port 80 packet allowed in, but the outbound check fails due to no matching allow rule, so the packet is dropped when leaving. Understanding this flow helps secure Azure resources effectively.

Practice

(1/5)
1. What is the primary purpose of an Azure Network Security Group (NSG)?
easy
A. To store data securely in the cloud
B. To manage user identities and access
C. To control inbound and outbound network traffic to resources
D. To monitor application performance

Solution

  1. Step 1: Understand NSG function

    NSGs are designed to filter network traffic to and from Azure resources.
  2. Step 2: Compare options

    Only To control inbound and outbound network traffic to resources describes controlling inbound and outbound traffic, which matches NSG's role.
  3. Final Answer:

    To control inbound and outbound network traffic to resources -> Option C
  4. Quick Check:

    NSG controls traffic = B [OK]
Hint: NSG controls traffic flow, not data or users [OK]
Common Mistakes:
  • Confusing NSG with storage or identity services
  • Thinking NSG monitors performance
  • Assuming NSG manages user access
2. Which of the following is the correct way to specify an inbound NSG rule to allow TCP traffic on port 80?
easy
A. Priority: 100, Direction: Inbound, Protocol: TCP, Port: 80, Action: Allow
B. Priority: 100, Direction: Inbound, Protocol: UDP, Port: 80, Action: Allow
C. Priority: 100, Direction: Outbound, Protocol: TCP, Port: 80, Action: Allow
D. Priority: 100, Direction: Inbound, Protocol: TCP, Port: 443, Action: Allow

Solution

  1. Step 1: Identify direction and protocol

    The question asks for inbound TCP traffic on port 80, so Direction must be Inbound and Protocol TCP.
  2. Step 2: Check port and action

    Port must be 80 and Action Allow to permit traffic.
  3. Final Answer:

    Priority: 100, Direction: Inbound, Protocol: TCP, Port: 80, Action: Allow -> Option A
  4. Quick Check:

    Inbound TCP port 80 allow = C [OK]
Hint: Inbound + TCP + port 80 + Allow = correct rule [OK]
Common Mistakes:
  • Using outbound direction instead of inbound
  • Using UDP protocol instead of TCP
  • Specifying wrong port number
3. Given these NSG rules applied in order of priority:
1) Priority 100: Allow inbound TCP port 22 from 10.0.0.0/24
2) Priority 200: Deny inbound TCP port 22 from any
What will happen if a connection attempt comes from IP 10.0.0.5 on port 22?
medium
A. The connection is allowed because allow rule has higher priority
B. The connection is allowed because deny rules do not apply to private IPs
C. The connection is denied because default deny applies
D. The connection is denied because deny rule has higher priority

Solution

  1. Step 1: Understand rule priority

    Lower priority number means higher priority. Priority 100 rule is evaluated before 200.
  2. Step 2: Evaluate matching rules

    IP 10.0.0.5 matches allow rule at priority 100, so connection is allowed before deny rule is checked.
  3. Final Answer:

    The connection is allowed because allow rule has higher priority -> Option A
  4. Quick Check:

    Lower priority allow beats higher priority deny = D [OK]
Hint: Lower priority number rules apply first [OK]
Common Mistakes:
  • Assuming deny always overrides allow
  • Ignoring rule priority order
  • Thinking private IPs bypass deny rules
4. You created an NSG rule to allow outbound HTTPS traffic on port 443, but traffic is still blocked. Which of the following is the most likely cause?
medium
A. The source IP address range is set to 0.0.0.0/0
B. The NSG rule is set to inbound instead of outbound
C. The protocol is set to UDP instead of TCP
D. There is a higher priority outbound deny rule blocking port 443

Solution

  1. Step 1: Check rule priority and direction

    If traffic is blocked despite allow rule, a deny rule with higher priority likely blocks it.
  2. Step 2: Evaluate other options

    Inbound vs outbound mismatch or protocol mismatch would cause no effect, but the question states rule exists for outbound HTTPS.
  3. Final Answer:

    There is a higher priority outbound deny rule blocking port 443 -> Option D
  4. Quick Check:

    Higher priority deny blocks traffic despite allow = A [OK]
Hint: Check for higher priority deny rules first [OK]
Common Mistakes:
  • Ignoring rule priority order
  • Confusing inbound and outbound directions
  • Assuming source IP 0.0.0.0/0 blocks traffic
5. You want to allow inbound HTTP traffic only from a specific IP range 192.168.1.0/24 and deny all other inbound HTTP traffic. Which NSG rule configuration achieves this?
hard
A. Priority 100: Deny inbound TCP port 80 from any; Priority 200: Allow inbound TCP port 80 from 192.168.1.0/24
B. Priority 100: Allow inbound TCP port 80 from 192.168.1.0/24; Priority 200: Deny inbound TCP port 80 from any
C. Priority 100: Allow inbound TCP port 80 from any; Priority 200: Deny inbound TCP port 80 from 192.168.1.0/24
D. Priority 100: Deny inbound TCP port 80 from 192.168.1.0/24; Priority 200: Allow inbound TCP port 80 from any

Solution

  1. Step 1: Allow specific IP range first

    Allow rule with higher priority (lower number) must permit traffic from 192.168.1.0/24.
  2. Step 2: Deny all other IPs

    Deny rule with lower priority blocks all other inbound HTTP traffic.
  3. Final Answer:

    Priority 100: Allow inbound TCP port 80 from 192.168.1.0/24; Priority 200: Deny inbound TCP port 80 from any -> Option B
  4. Quick Check:

    Allow specific IP first, then deny others = A [OK]
Hint: Allow specific IP with lower priority number, deny others after [OK]
Common Mistakes:
  • Placing deny rule before allow rule
  • Allowing all IPs instead of specific range
  • Using wrong priority numbers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard