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.
π Please sign in to launch lab.
ποΈ Pre-Provisioned Environment
The following Azure resources have been pre-deployed with intentional misconfigurations:
Resource Overview
Resource Type | Resource Name | Configuration | Purpose |
---|---|---|---|
Resource Group | NSG-Eval-Lab | Contains all lab resources | Logical container |
Virtual Network | EvalVNet | Address space: 10.0.0.0/16 | Network foundation |
Frontend Subnet | FrontendSubnet | Range: 10.0.1.0/24 | Web tier network |
Backend Subnet | BackendSubnet | Range: 10.0.2.0/24 | App tier network |
Frontend VM | FrontendVM | Windows Server 2019 | Client VM |
Backend VM | BackendVM | Ubuntu with web server | Target VM |
Frontend NSG | Frontend-NSG | Misconfigured | Frontend protection |
Backend NSG | Backend-NSG | Misconfigured | Backend 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
VM | Private IP | Operating System | Role |
---|---|---|---|
FrontendVM | 10.0.1.4 | Windows Server 2019 | HTTP client |
BackendVM | 10.0.2.4 | Ubuntu 20.04 + Apache | Web server |
π Lab Tasks
Task 1: Verify Connectivity Issue
Step 1: Connect to Frontend VM
- Navigate to NSG-Eval-Lab resource group
- Click on FrontendVM
- Click Connect β RDP
- Use the following credentials:
- Username:
azureuser
- Password:
LabPassword123!
- Username:
Step 2: Test Web Server Connectivity
Once connected to FrontendVM, open Command Prompt and run:
# Test HTTP connectivity to BackendVMcurl http://10.0.2.4
# Alternative: Use PowerShellpowershell -Command "Invoke-WebRequest -Uri http://10.0.2.4 -TimeoutSec 10"
# Test basic network connectivityping 10.0.2.4
# Test port connectivitytelnet 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
- Navigate to Backend-NSG
- Click Inbound security rules
- Analyze the rules:
Rule Name | Priority | Source | Port | Action | Issue? |
---|---|---|---|---|---|
Default rules | 65000+ | Various | Various | Allow/Deny | Check for blocks |
Custom rules | < 4096 | Check source | Check port 80 | Check action | Look 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
- Navigate to Frontend-NSG
- Click Outbound security rules
- Look for blocking rules:
Rule Analysis | Check For | Expected Value |
---|---|---|
Destination | BackendSubnet range | 10.0.2.0/24 |
Port | HTTP traffic | 80 or Any |
Action | Traffic permission | Allow |
Priority | Rule conflicts | Lower number = higher priority |
Task 3: Use Azure Network Watcher Diagnostics
Step 1: Access Network Watcher
- In Azure Portal, search for βNetwork Watcherβ
- Select Network Watcher service
- Ensure itβs enabled in your region
Step 2: Run Connection Troubleshoot
- Click Connection troubleshoot in the left menu
- Configure the test:
Setting | Value | Purpose |
---|---|---|
Subscription | Your subscription | Target subscription |
Resource Group | NSG-Eval-Lab | Lab resources |
Source type | Virtual machine | Test source |
Virtual machine | FrontendVM | Source VM |
Destination | Specify manually | Custom target |
URI, FQDN or IPv4 | 10.0.2.4 | BackendVM IP |
Protocol | TCP | HTTP protocol |
Destination Port | 80 | HTTP port |
- Click Check
Step 3: Analyze Results
Review the diagnostic output:
Result Type | Meaning | Action Required |
---|---|---|
Reachable | Connection successful | No action needed |
Unreachable | Connection blocked | Check blocking component |
Unknown | Indeterminate result | Re-run test |
Step 4: Examine Hop Details
- Click on View details for each hop
- 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
- Navigate to BackendVM
- Click Networking in the left menu
- Click Effective security rules
Step 2: Analyze Inbound Rules
Look for rules affecting port 80:
Priority | Name | Source | Port | Action | Evaluation |
---|---|---|---|---|---|
Lower # | Rule name | IP range | 80 | Allow/Deny | Blocking 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)
- Navigate to Backend-NSG
- Click Inbound security rules
- Option A: Modify existing rule
- Find the problematic rule
- Click on the rule name
- Correct the configuration:
Setting | Correct Value | Purpose |
---|---|---|
Source | 10.0.1.0/24 or VirtualNetwork | Allow Frontend subnet |
Destination port ranges | 80 | HTTP traffic |
Action | Allow | Permit traffic |
- Option B: Create new rule
- Click + Add
- Configure proper rule:
Setting | Value | Purpose |
---|---|---|
Source | IP Addresses | Specific source |
Source IP addresses | 10.0.1.0/24 | Frontend subnet |
Destination port ranges | 80 | HTTP port |
Protocol | TCP | HTTP protocol |
Action | Allow | Permit traffic |
Priority | 100 | High priority |
Name | Allow-HTTP-Frontend | Descriptive name |
- Click Add
Step 2: Fix Frontend NSG (If Required)
- Navigate to Frontend-NSG
- Click Outbound security rules
- If needed, add or modify rule:
Setting | Value | Purpose |
---|---|---|
Destination | IP Addresses | Specific destination |
Destination IP addresses | 10.0.2.0/24 | Backend subnet |
Destination port ranges | 80 | HTTP traffic |
Action | Allow | Permit traffic |
Priority | 100 | High priority |
Name | Allow-HTTP-Backend | Descriptive name |
Task 6: Validate the Fix
Step 1: Test Connectivity Again
Return to FrontendVM and test:
# Test HTTP connectivitycurl http://10.0.2.4
# Test with PowerShell for detailed outputpowershell -Command "Invoke-WebRequest -Uri http://10.0.2.4"
# Test port connectivitytelnet 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
- Return to Network Watcher β Connection troubleshoot
- Re-run the same test configuration
- Verify: Result should now show Reachable
Step 3: Verify Effective Rules
- Go back to BackendVM β Networking β Effective security rules
- Confirm: Your new allow rule appears with correct priority
- Check: No higher-priority deny rules are blocking traffic
π§ Troubleshooting Guide
Common NSG Issues and Solutions
Issue | Symptoms | Solution |
---|---|---|
Deny rule higher priority | Traffic blocked despite allow rule | Lower the allow rule priority number |
Wrong source IP range | Specific IPs blocked | Update source to include correct IP range |
Missing port in rule | Specific port blocked | Add required port to destination port ranges |
Outbound rule blocking | Return traffic fails | Check outbound rules on source NSG |
Default rule conflict | Unexpected behavior | Add explicit rules with higher priority |
NSG Rule Evaluation Logic
- Process inbound rules by priority (lowest number first)
- First matching rule determines action (Allow or Deny)
- If no custom rules match, default rules apply
- Stateful connection - return traffic automatically allowed
Network Watcher Diagnostic Codes
Status | Meaning | Next Steps |
---|---|---|
Reachable | Connection successful | No action needed |
Unreachable | NSG or firewall blocking | Check NSG rules and VM firewall |
DNS resolution failed | Name resolution issue | Check DNS configuration |
Timeout | Network or application timeout | Check application and network latency |
π§ͺ Additional Experiments
Try these optional exercises to deepen your understanding:
- Priority Testing: Create conflicting rules with different priorities
- Service Tags: Use service tags instead of IP addresses
- Application Security Groups: Implement ASGs for more granular control
- Flow Logs: Enable and analyze NSG flow logs
- 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
- Verify symptoms - Test actual connectivity
- Check NSG rules - Review source, destination, ports
- Use diagnostics - Leverage Network Watcher tools
- Analyze effective rules - Understand combined rule effects
- Implement fixes - Modify or add appropriate rules
- 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