Skip to content

NSGs - Evaluate

🎯 Lab Objective

In this hands-on lab, you will learn how to:

  • Evaluate effective NSG rules and understand rule precedence
  • Use Azure Network Watcher for connectivity troubleshooting
  • Diagnose NSG-related connectivity issues using built-in tools
  • Implement proper NSG rule fixes to restore connectivity
  • Understand NSG rule evaluation logic and traffic flow

Scenario: You are unable to connect from FrontendVM to BackendVM over port 80 (HTTP). Your task is to investigate and fix the issue using NSG rule evaluation and diagnostics.


πŸ—οΈ Pre-Provisioned Environment

The following Azure resources have been pre-deployed with intentional misconfigurations:

Resource Overview

Resource TypeResource NameConfigurationPurpose
Resource GroupNSG-Eval-LabContains all lab resourcesLogical container
Virtual NetworkEvalVNetAddress space: 10.0.0.0/16Network foundation
Frontend SubnetFrontendSubnetRange: 10.0.1.0/24Web tier network
Backend SubnetBackendSubnetRange: 10.0.2.0/24App tier network
Frontend VMFrontendVMWindows Server 2019Client VM
Backend VMBackendVMUbuntu with web serverTarget VM
Frontend NSGFrontend-NSGMisconfiguredFrontend protection
Backend NSGBackend-NSGMisconfiguredBackend protection

Network Architecture

EvalVNet (10.0.0.0/16)
β”œβ”€β”€ FrontendSubnet (10.0.1.0/24)
β”‚ └── FrontendVM (Windows Server)
β”‚ └── Frontend-NSG (❌ Blocking traffic)
└── BackendSubnet (10.0.2.0/24)
└── BackendVM (Ubuntu + Apache)
└── Backend-NSG (❌ Blocking traffic)

VM Details

VMPrivate IPOperating SystemRole
FrontendVM10.0.1.4Windows Server 2019HTTP client
BackendVM10.0.2.4Ubuntu 20.04 + ApacheWeb server

πŸš€ Lab Tasks

Task 1: Verify Connectivity Issue

Step 1: Connect to Frontend VM

  1. Navigate to NSG-Eval-Lab resource group
  2. Click on FrontendVM
  3. Click Connect β†’ RDP
  4. Use the following credentials:
    • Username: azureuser
    • Password: LabPassword123!

Step 2: Test Web Server Connectivity

Once connected to FrontendVM, open Command Prompt and run:

Terminal window
# Test HTTP connectivity to BackendVM
curl http://10.0.2.4
# Alternative: Use PowerShell
powershell -Command "Invoke-WebRequest -Uri http://10.0.2.4 -TimeoutSec 10"
# Test basic network connectivity
ping 10.0.2.4
# Test port connectivity
telnet 10.0.2.4 80

Step 3: Document the Issue

Expected Behavior:

  • ❌ HTTP connection should fail or timeout
  • ❌ Ping may fail depending on ICMP rules
  • ❌ Telnet to port 80 should fail

πŸ“ Note: Record the specific error messages you receive for later analysis.


Task 2: Inspect NSG Rules

Step 1: Examine Backend NSG Rules

  1. Navigate to Backend-NSG
  2. Click Inbound security rules
  3. Analyze the rules:
Rule NamePrioritySourcePortActionIssue?
Default rules65000+VariousVariousAllow/DenyCheck for blocks
Custom rules< 4096Check sourceCheck port 80Check actionLook for problems

Step 2: Check Rule Details

For each custom rule, verify:

  • Source: Does it allow traffic from 10.0.1.0/24 (FrontendSubnet)?
  • Destination Port: Is port 80 explicitly allowed?
  • Action: Is the action set to Allow?
  • Priority: Are there conflicting rules with higher priority?

Step 3: Examine Frontend NSG Rules

  1. Navigate to Frontend-NSG
  2. Click Outbound security rules
  3. Look for blocking rules:
Rule AnalysisCheck ForExpected Value
DestinationBackendSubnet range10.0.2.0/24
PortHTTP traffic80 or Any
ActionTraffic permissionAllow
PriorityRule conflictsLower number = higher priority

Task 3: Use Azure Network Watcher Diagnostics

Step 1: Access Network Watcher

  1. In Azure Portal, search for β€œNetwork Watcher”
  2. Select Network Watcher service
  3. Ensure it’s enabled in your region

Step 2: Run Connection Troubleshoot

  1. Click Connection troubleshoot in the left menu
  2. Configure the test:
SettingValuePurpose
SubscriptionYour subscriptionTarget subscription
Resource GroupNSG-Eval-LabLab resources
Source typeVirtual machineTest source
Virtual machineFrontendVMSource VM
DestinationSpecify manuallyCustom target
URI, FQDN or IPv410.0.2.4BackendVM IP
ProtocolTCPHTTP protocol
Destination Port80HTTP port
  1. Click Check

Step 3: Analyze Results

Review the diagnostic output:

Result TypeMeaningAction Required
ReachableConnection successfulNo action needed
UnreachableConnection blockedCheck blocking component
UnknownIndeterminate resultRe-run test

Step 4: Examine Hop Details

  1. Click on View details for each hop
  2. Look for NSG evaluation results:
    • Which NSG is blocking traffic?
    • Which specific rule is causing the block?
    • What’s the rule priority and action?

Task 4: Use Effective Security Rules

Step 1: View Effective Rules for Backend VM

  1. Navigate to BackendVM
  2. Click Networking in the left menu
  3. Click Effective security rules

Step 2: Analyze Inbound Rules

Look for rules affecting port 80:

PriorityNameSourcePortActionEvaluation
Lower #Rule nameIP range80Allow/DenyBlocking traffic?

Step 3: Identify the Problem Rule

Common issues to look for:

  • Deny rule with higher priority than allow rule
  • Source restriction not including FrontendSubnet
  • Port restriction not including port 80
  • Missing allow rule for the required traffic

Task 5: Fix NSG Configuration

Step 1: Fix Backend NSG (Most Likely Issue)

  1. Navigate to Backend-NSG
  2. Click Inbound security rules
  3. Option A: Modify existing rule
    • Find the problematic rule
    • Click on the rule name
    • Correct the configuration:
SettingCorrect ValuePurpose
Source10.0.1.0/24 or VirtualNetworkAllow Frontend subnet
Destination port ranges80HTTP traffic
ActionAllowPermit traffic
  1. Option B: Create new rule
    • Click + Add
    • Configure proper rule:
SettingValuePurpose
SourceIP AddressesSpecific source
Source IP addresses10.0.1.0/24Frontend subnet
Destination port ranges80HTTP port
ProtocolTCPHTTP protocol
ActionAllowPermit traffic
Priority100High priority
NameAllow-HTTP-FrontendDescriptive name
  1. Click Add

Step 2: Fix Frontend NSG (If Required)

  1. Navigate to Frontend-NSG
  2. Click Outbound security rules
  3. If needed, add or modify rule:
SettingValuePurpose
DestinationIP AddressesSpecific destination
Destination IP addresses10.0.2.0/24Backend subnet
Destination port ranges80HTTP traffic
ActionAllowPermit traffic
Priority100High priority
NameAllow-HTTP-BackendDescriptive name

Task 6: Validate the Fix

Step 1: Test Connectivity Again

Return to FrontendVM and test:

Terminal window
# Test HTTP connectivity
curl http://10.0.2.4
# Test with PowerShell for detailed output
powershell -Command "Invoke-WebRequest -Uri http://10.0.2.4"
# Test port connectivity
telnet 10.0.2.4 80

Expected Results:

  • βœ… HTTP connection should succeed
  • βœ… Should receive web page content
  • βœ… Port 80 should be reachable

Step 2: Re-run Network Watcher Test

  1. Return to Network Watcher β†’ Connection troubleshoot
  2. Re-run the same test configuration
  3. Verify: Result should now show Reachable

Step 3: Verify Effective Rules

  1. Go back to BackendVM β†’ Networking β†’ Effective security rules
  2. Confirm: Your new allow rule appears with correct priority
  3. Check: No higher-priority deny rules are blocking traffic

πŸ”§ Troubleshooting Guide

Common NSG Issues and Solutions

IssueSymptomsSolution
Deny rule higher priorityTraffic blocked despite allow ruleLower the allow rule priority number
Wrong source IP rangeSpecific IPs blockedUpdate source to include correct IP range
Missing port in ruleSpecific port blockedAdd required port to destination port ranges
Outbound rule blockingReturn traffic failsCheck outbound rules on source NSG
Default rule conflictUnexpected behaviorAdd explicit rules with higher priority

NSG Rule Evaluation Logic

  1. Process inbound rules by priority (lowest number first)
  2. First matching rule determines action (Allow or Deny)
  3. If no custom rules match, default rules apply
  4. Stateful connection - return traffic automatically allowed

Network Watcher Diagnostic Codes

StatusMeaningNext Steps
ReachableConnection successfulNo action needed
UnreachableNSG or firewall blockingCheck NSG rules and VM firewall
DNS resolution failedName resolution issueCheck DNS configuration
TimeoutNetwork or application timeoutCheck application and network latency

πŸ§ͺ Additional Experiments

Try these optional exercises to deepen your understanding:

  1. Priority Testing: Create conflicting rules with different priorities
  2. Service Tags: Use service tags instead of IP addresses
  3. Application Security Groups: Implement ASGs for more granular control
  4. Flow Logs: Enable and analyze NSG flow logs
  5. Multiple NSGs: Test with NSGs on both subnet and NIC levels

πŸŽ“ Key Takeaways

After completing this lab, you should understand:

  • NSG rule evaluation follows priority order (lowest number first)
  • Network Watcher provides powerful diagnostics for connectivity issues
  • Effective security rules show the combined result of all NSG rules
  • Stateful filtering allows return traffic automatically
  • Both inbound and outbound rules can affect connectivity
  • Default rules provide baseline connectivity within VNets

πŸ“Š NSG Troubleshooting Methodology

Systematic Approach

  1. Verify symptoms - Test actual connectivity
  2. Check NSG rules - Review source, destination, ports
  3. Use diagnostics - Leverage Network Watcher tools
  4. Analyze effective rules - Understand combined rule effects
  5. Implement fixes - Modify or add appropriate rules
  6. Validate resolution - Re-test connectivity

Best Practices for NSG Rules

  • Use descriptive names for easy identification
  • Set appropriate priorities to avoid conflicts
  • Document rule purposes in descriptions
  • Test changes in non-production first
  • Monitor with flow logs for ongoing analysis

πŸ“š Additional Resources