Configuring NSGs for Peering Security
Learn how to configure Network Security Groups for secure Azure virtual network peering, addressing common risks and implementing best practices.
Want to secure your Azure virtual networks? Network Security Groups (NSGs) are your go-to solution for controlling traffic between peered networks. This guide breaks down how to use NSGs to safeguard your peered virtual networks effectively.
Here’s what you’ll learn:
- What NSGs are: Virtual firewalls that filter traffic based on rules you define.
- Why peering security matters: Misconfigured NSGs can expose sensitive data and systems.
- Common risks: Overly permissive rules and poor traffic management can lead to vulnerabilities.
- How NSGs help: They enforce strict traffic control, align with zero trust principles, and provide logging for monitoring.
Key steps include:
- Reviewing existing NSG rules to spot overly broad access.
- Creating precise rules to allow only required traffic.
- Assigning NSGs to subnets or network interfaces.
- Testing and verifying configurations using tools like Azure Network Watcher.
- Enabling NSG flow logs for monitoring and compliance.
Best practices:
- Use the principle of least privilege for all rules.
- Regularly review and update configurations to align with business needs.
- Document every change for clarity and audits.
- Automate with PowerShell or Azure CLI for consistency.
Virtual Network Peering and Security Risks
What is Virtual Network Peering?
Virtual network peering in Azure allows you to establish a private, direct connection between two or more virtual networks (VNets). This connection uses Azure's internal backbone infrastructure, bypassing the public internet. The result? Better performance, reduced latency, and a secure channel for data transfer.
Peering can connect VNets within the same Azure region, across different regions, or even between separate subscriptions and Microsoft Entra tenants. Once the connection is in place, resources in these VNets can communicate using their private IP addresses. This makes it ideal for scenarios like sharing services between departments, creating multi-tier applications, or setting up cross-region disaster recovery plans.
That said, while peering simplifies connectivity, it can introduce risks if not properly managed.
Common Security Risks in Peering
Despite its advantages, peering comes with potential security pitfalls. Misconfigured Network Security Groups (NSGs) can result in overly permissive access between peered VNets. This can lead to lateral movement across the network, increasing vulnerability. For instance, if a development virtual machine is compromised, it might gain access to sensitive production databases through open Remote Desktop Protocol (RDP) connections.
Another issue arises from poorly managed traffic flows. Default or overly permissive rules can allow unwanted inbound or outbound traffic, exposing critical workloads to unauthorised access. Without proper logging and monitoring, identifying and investigating unauthorised cross-traffic becomes a daunting task.
How NSGs Improve Peering Security
Network Security Groups (NSGs) play a vital role in addressing these risks. Acting as virtual firewalls, NSGs control and filter all traffic between peered VNets. By setting specific rules, they ensure that only authorised communication is allowed, while all other traffic is blocked.
NSGs evaluate traffic based on factors like source and destination IP addresses, ports, and protocols. For example, you can configure an NSG to allow only HTTP and HTTPS traffic from a web-tier subnet to an application-tier subnet, while denying all other types of traffic. This segmentation enforces strict boundaries, making it harder for attackers to move laterally across the network, even if one part is compromised. This approach aligns with the zero trust principle, where no connection is automatically trusted.
Additionally, NSGs provide valuable logging features. Enabling NSG flow logs allows you to monitor both allowed and denied traffic, helping you detect suspicious behaviour and maintain compliance with UK data protection regulations. For organisations that need to demonstrate strong security measures to auditors or regulators, this level of visibility is essential.
Prerequisites and Planning for NSG Setup
What You Need Before Starting
To configure Network Security Groups (NSGs) for peering security, you'll need a few essentials in place. First, ensure you have an active Azure subscription - without it, you can't create or manage NSGs. Additionally, your Azure account must have Network Contributor or Owner permissions. These permissions are also critical for setting up and managing virtual network peering, a key component of the process.
Familiarity with tools like the Azure Portal, PowerShell, or Azure CLI can make your workflow much smoother, especially when automating tasks or handling bulk operations.
Before diving into NSG rules, confirm that your virtual network peering is fully established and in the "Connected" state on both sides. Without this, communication between peered networks won't work, and premature security rule configuration could lead to unnecessary delays.
Lastly, take a moment to review Azure's NSG limitations regarding IP addresses and CIDR ranges. Overlooking these constraints can result in deployment errors that are easily avoidable with proper preparation.
Once you've checked off these prerequisites, you can move on to planning your NSG deployment.
Planning Your Peering Security
Careful planning is the foundation of effective NSG deployment. Start by documenting your network architecture in detail. This includes mapping out all subnets, peered virtual networks, and their respective IP address ranges. This blueprint will guide you in creating accurate rules and help prevent misconfigurations that could compromise security or disrupt connectivity.
Clearly define the traffic flows required between your peered networks. Identify the specific resources and services that need to communicate, as well as the protocols, ports, and traffic direction for each connection. For instance, if a web server in one virtual network needs to interact with a database in another, specify the source and destination IP ranges along with the necessary ports. This level of detail helps close potential security gaps while avoiding overly permissive access.
According to Microsoft's data, misconfigured NSGs are a major cause of Azure networking support cases. This highlights the importance of thorough planning, as many issues stem from rushed implementations where traffic requirements aren't fully mapped out.
For larger or more dynamic environments, consider using Application Security Groups (ASGs). ASGs simplify NSG rule management by grouping virtual machines with similar roles, allowing you to apply consistent security policies more efficiently. However, keep in mind that ASGs used as both the source and destination in NSG rules must be within the same virtual network - they cannot span peered networks.
It's also wise to plan for future network growth. Document any expected changes, such as new address spaces or applications that might require network access. Anticipating these needs can help you avoid rule conflicts and reduce the need for constant reconfiguration.
Finally, build regular review schedules into your planning process. With the increasing focus on least privilege and zero trust principles, NSG configurations must be continuously updated to align with current business and security needs. Regular reviews ensure your rules remain effective and relevant.
For small and medium-sized businesses, the Azure Optimization Tips, Costs & Best Practices blog offers practical advice on creating secure and cost-efficient NSG and peering setups.
Azure Virtual Networks and NSGs Explained | Secure Your Cloud Infrastructure (Full Tutorial)

Step-by-Step Guide: Setting Up NSGs for Peering Security
Once you've planned your Network Security Groups (NSGs), it's time to secure your peered connections by following these steps.
Review Current NSG Rules
Start by examining the existing NSG rules for your peered networks. In the Azure portal, go to "Network Security Groups" and review the inbound and outbound rules for each NSG. Pay close attention to rules that affect traffic from peered network address ranges, especially those that are too permissive, such as rules allowing all traffic from any source (0.0.0.0/0).
You can also use PowerShell (Get-AzNetworkSecurityGroup) or Azure CLI (az network nsg list) to export and document these rules. Keeping a record serves compliance needs and provides a reference for rolling back changes if needed.
Create or Update NSGs for Peered Subnets
Update or create NSGs to allow only the necessary protocols, ports, and address ranges. Stick to the principle of least privilege - this means creating inbound rules that only permit essential traffic. For instance, if you need to enable RDP access (port 3389) from a specific peered subnet, define an inbound rule with the source set to that subnet's address range (e.g., 10.1.0.0/16) and the destination port as 3389. Remove or adjust any overly permissive rules.
Here’s an example of an NSG rule configuration:
| NSG Rule Parameter | Description | Example Value |
|---|---|---|
| Name | Name of the rule | Allow-Peering-RDP |
| Priority | Rule processing order | 200 |
| Source | IP, CIDR, Service Tag, ASG | 10.1.0.0/16 |
| Destination | IP, CIDR, Service Tag, ASG | 10.2.0.0/16 |
| Protocol | TCP, UDP, ICMP, or Any | TCP |
| Port Range | Single port or range | 3389 |
| Action | Allow or Deny | Allow |
To simplify rule creation, use Azure’s built-in service tags like VirtualNetwork, Internet, and AzureLoadBalancer. These tags automatically adjust to changes in Azure’s infrastructure. Always document any changes you make, including the business justification, the date of implementation (in DD/MM/YYYY format), and the person responsible. This helps with audits and rollback processes.
Apply NSGs to Subnets or Network Interfaces
Assign NSGs to the appropriate subnets or network interfaces within your peered networks. For subnets, navigate to the "Subnets" section of your virtual network, select the target subnet, and attach the relevant NSG. For network interfaces, locate the specific NIC and assign the NSG under the "Network security group" settings.
To ensure consistency across multiple subnets, use PowerShell (Set-AzVirtualNetworkSubnetConfig) or Azure CLI (az network vnet subnet update).
Test and Verify Your Setup
Test your configuration by using network tools and checking NSG flow logs. Deploy test virtual machines in each peered subnet and attempt to connect using the allowed protocols and ports. Verify that unauthorised traffic is blocked, ensuring your NSGs enforce strict security boundaries.
If you encounter connectivity issues, Azure Network Watcher can help diagnose the problem. Review the effective security rules applied to the affected subnets or network interfaces to pinpoint the issue.
Using PowerShell and CLI for NSG Setup

For UK organisations managing multiple NSGs, automation with PowerShell or Azure CLI can save time and ensure consistency. Stick to naming conventions and locations that align with UK standards (e.g., uksouth).
Here’s how to create an NSG rule using PowerShell:
Add-AzNetworkSecurityRuleConfig -Name "Allow-RDP" -NetworkSecurityGroup $nsg -Priority 100 -Direction Inbound -Access Allow -Protocol Tcp -SourceAddressPrefix "10.1.0.0/16" -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389
And the equivalent Azure CLI command:
az network nsg rule create --resource-group myResourceGroup --nsg-name myNSG --name Allow-RDP --priority 100 --direction Inbound --access Allow --protocol Tcp --source-address-prefixes 10.1.0.0/16 --destination-port-ranges 3389
To create and assign NSGs, use New-AzNetworkSecurityGroup and Set-AzVirtualNetworkSubnetConfig in PowerShell, or az network nsg create and az network vnet subnet update in Azure CLI.
For more tips on building secure and cost-effective NSG and peering setups, check out the Azure Optimization Tips, Costs & Best Practices blog.
Keep in mind: Peering does not bypass NSG rules. Even after establishing peering, NSGs will continue to enforce security boundaries, so you must explicitly create rules to allow the required traffic between peered networks.
With your NSGs in place and thoroughly tested, you can move on to monitoring and reviewing your setup in the next steps.
Best Practices for Securing Peered Connections with NSGs
After configuring and testing your Network Security Groups (NSGs), it's essential to follow these practices to maintain strong security for peered networks while ensuring smooth operations.
Allow Only Minimum Required Access
To strengthen your NSG setup, enforce strict access controls between peered networks by adopting a "least privilege" approach. This means only allowing the traffic that is absolutely necessary for your applications to function.
Microsoft reports that misconfigured NSGs account for over 60% of security incidents in Azure environments, often due to overly permissive rules or a lack of regular reviews.
Start with default deny rules, then add specific allow rules for the required ports, protocols, and IP ranges. For instance, if your web app only needs HTTPS, create a rule that permits TCP port 443 from a specific subnet (e.g., 10.1.0.0/16) instead of opening access to the entire virtual network.
Simplify rule management by using service tags, such as VirtualNetwork, AzureLoadBalancer, and Storage. These tags automatically adapt to Azure infrastructure changes, reducing the risk of errors when managing traffic across peered networks.
Consider adopting a Zero Trust security model in Azure. This approach assumes every connection could be a threat, requiring verification before granting access. It ensures that only the minimum required access is granted for communications, even over peered connections.
For workloads with similar security needs, Application Security Groups (ASGs) can help streamline rule management. They allow you to group virtual machines logically and apply rules based on application tiers instead of specific IP addresses.
Regular Rule Reviews and Monitoring
Schedule periodic reviews of your NSG rules - quarterly or after major infrastructure changes - to ensure they still align with security and business needs. These reviews can help identify and remove outdated or overly permissive rules that could expose your network to risks.
Keep detailed documentation of your NSG rules, including implementation dates (in DD/MM/YYYY format), responsible personnel, and the business reasons for each rule. This supports audits and troubleshooting efforts. Use Azure Monitor to track NSG changes and set up alerts for any additions, modifications, or deletions.
After making changes to NSG rules, test network connectivity between peered subnets to confirm that only authorised traffic is allowed. Deploy test virtual machines in the subnets and attempt connections using both permitted and blocked protocols. This ensures your rules are functioning as intended.
Enable Logging and Traffic Monitoring
Enable NSG flow logs and integrate them with Azure Monitor or a SIEM system for real-time alerts and historical analysis.
"Enabling NSG flow logs improves incident response through enhanced traffic visibility".
Flow logs record all traffic, providing valuable data for incident response, forensic analysis, and compliance reporting. This makes them an essential tool for maintaining a secure environment.
Set up automated alerts to flag denied traffic attempts, especially from peered networks. Patterns of denied traffic could signal reconnaissance attempts or misconfigurations needing immediate attention. Azure Monitor can notify you of suspicious activity, such as multiple denied connections from the same source IP in a short timeframe.
Use Azure Network Watcher alongside NSG flow logs for deeper insights into traffic patterns and potential security issues. Tools like Connection Monitor and Traffic Analytics can help you identify bottlenecks or vulnerabilities in your peered network traffic.
Finally, enforce NSG deployment and configuration standards across all peered networks using Azure Policy. This tool detects non-compliant configurations and can either alert administrators or automatically fix issues, ensuring consistent security standards throughout your Azure environment.
For more tips on balancing security with cost efficiency in your NSG and peering setups, check out the Azure Optimization Tips, Costs & Best Practices blog, which offers practical advice tailored for small and medium businesses scaling on Microsoft Azure.
Troubleshooting and Checking Your Setup
Network Security Group (NSG) configurations can sometimes lead to connectivity challenges between peered networks. Being able to identify and resolve these issues promptly is crucial to keeping your applications running smoothly.
Fixing Common NSG Problems
Some of the most frequent NSG issues include overly restrictive rules, conflicting configurations, or missing allowances for essential ports and protocols. These problems often arise when administrators apply broad deny rules without fully accounting for the specific communication needs of peered virtual networks.
One key area to check is rule priority. In NSGs, lower numbers take precedence over higher ones. If your applications are failing to communicate across peered networks, it’s worth verifying whether a high-priority deny rule is unintentionally blocking traffic that a lower-priority allow rule was intended to permit.
For instance, a default rule blocking all inbound traffic might prevent an application server from accessing a database in a peered network. To fix this, you’d need to create specific allow rules for the required database ports (e.g., TCP 1433 for SQL Server) and limit the source to the application subnet. This approach restores functionality while maintaining security.
Application Security Groups (ASGs) can also cause issues. For ASGs to work in NSG rules, both the source and destination ASGs must exist within the same virtual network. If you’re using ASGs in a peered network setup, double-check that they are defined within the correct network scope.
To address overly restrictive rules, review the NSGs applied to subnets or network interfaces on both sides of the peered connection. Explicitly allow the traffic required for your applications to function. Tools like Azure diagnostics can help verify whether your adjustments have resolved the issue.
Using Azure Diagnostic Tools
Azure offers several diagnostic tools to help troubleshoot connectivity problems between peered networks. Tools like Network Watcher and NSG flow logs provide detailed insights into traffic behaviour and potential blockages.
Start by enabling NSG flow logs in Network Watcher to capture traffic data. These logs can reveal patterns of denied connections or unexpected flows. The Connection Troubleshoot feature, also part of Network Watcher, lets you test connectivity between specific resources to pinpoint where traffic might be blocked.
According to Microsoft, misconfigured NSGs are among the leading causes of connectivity issues in Azure virtual networks, accounting for a significant number of support cases related to network access problems.
You can also use PowerShell cmdlets, such as Get-AzNetworkSecurityGroup and Get-AzVirtualNetworkPeering, to review current configurations. For updates, commands like Set-AzNetworkSecurityGroup or Set-AzVirtualNetworkPeering can modify settings. If you prefer Azure CLI, commands like az network nsg list, az network vnet peering list, and az network nsg rule update offer similar capabilities.
NSG flow logs can also be integrated with Azure Monitor for real-time alerts and historical analysis. For example, you can set up automated alerts to flag unusual patterns, such as repeated denied connections from the same IP address. This could signal a misconfiguration or even a potential security threat requiring immediate attention.
These tools don’t just help fix problems - they also provide ongoing visibility, ensuring your network remains secure and functional.
Checking Your Peering Security
Once you’ve adjusted your NSG rules and resolved connectivity issues, it’s important to verify that your peered networks remain secure. Start by checking that the peering status for both networks is "Connected", as resources won’t communicate until this status is achieved.
Deploy test virtual machines (VMs) and confirm connectivity using tools like ping, PowerShell’s Test-NetConnection, or Network Watcher’s Connection Troubleshoot feature. If communication still fails, revisit your NSG rules and flow logs to identify any remaining issues.
Regular security audits are a good practice. Use tools like Azure Security Centre or third-party solutions to detect misconfigurations or non-compliant settings. Azure Policy can enforce compliance standards, ensuring your NSG configurations align with organisational requirements.
To maintain transparency and support troubleshooting, document all NSG changes. Include details like the implementation date (DD/MM/YYYY), the person responsible, and the business justification for each rule. This record will also help with compliance verification during audits.
For UK-based small and medium-sized businesses (SMBs), it’s essential to consider local regulations like GDPR when configuring logging and monitoring. Ensure that NSG flow logs and diagnostic data are stored in compliance with data protection laws, and monitor costs in GBP to keep budgets in check.
Finally, remember that NSG rules are stateful. If an inbound rule allows traffic, the corresponding response traffic is automatically permitted. While this simplifies troubleshooting, it’s important to ensure outbound rules are properly configured to avoid unintended access.
To minimise risks, implement a structured change management process. This should include peer reviews, testing in non-production environments, and automated validation using Azure Policy or Security Centre. After making changes, use diagnostic tools to confirm that only the intended traffic is allowed and that no unnecessary exposure has been introduced.
For more tips on securing and optimising your Azure environment, particularly for UK-based SMBs, check out Azure Optimization Tips, Costs & Best Practices.
Key Points for Configuring NSGs for Peering Security
Securing virtual network peering with Network Security Groups (NSGs) requires a balance between accessibility and robust protection. Since NSGs operate at the subnet or network interface level - rather than on the peering connection itself - you’ll need to implement security controls on the relevant subnets within each peered network.
Summary of Steps and Best Practices
Start by reviewing your existing NSG rules to identify and address any security gaps. Pay close attention to rule priorities, as lower numbers are evaluated first, potentially overriding higher-priority rules.
Adopt a "least privilege" approach by allowing only essential traffic. For example, limit RDP access (TCP port 3389) to specific, authorised sources. Use service tags like VirtualNetwork and Application Security Groups to simplify and standardise rule management. For broader protection, apply NSGs at the subnet level, or for more precise control, configure them at the network interface level.
Test your configurations thoroughly using tools such as Test-NetConnection or Connection Troubleshoot. These tools help verify that legitimate traffic is allowed while blocking unauthorised flows. To streamline ongoing management, leverage automation tools like PowerShell (Get-AzNetworkSecurityGroup) or Azure CLI (az network nsg list) for consistent NSG rule updates and audits.
By following these practices, you can maintain a secure and manageable peering setup across your virtual networks.
Next Steps for SMBs
Building on these best practices, small and medium-sized businesses (SMBs) can take additional steps to ensure NSG security remains effective over time.
- Schedule Regular Reviews: Network security isn’t a one-time task. Regularly review NSG rules to adapt to changes in your network architecture and business needs.
- Enable NSG Flow Logs: Integrate NSG flow logs with Azure Monitor to track traffic patterns and detect anomalies. This proactive monitoring can help identify unauthorised access attempts and ensure compliance with UK-specific regulations, such as GDPR and data residency requirements.
- Document Changes: Keep detailed records of NSG changes, including the implementation date (DD/MM/YYYY), responsible team member, and the rationale behind each change. This documentation is invaluable for compliance audits and helps maintain organisational knowledge as your team grows.
- Manage Costs: While NSGs are free, logging and monitoring features may incur additional costs based on data volume and retention settings. Regularly review and optimise rules to minimise unnecessary data transfer and associated costs.
Establishing a structured change management process is also essential. This should include peer reviews, testing in non-production environments, and automated validation using tools like Azure Policy or Security Centre. Such a process reduces risks and ensures a strong security posture.
For SMBs in the UK, managing costs and security can be challenging. Resources like Azure Optimization Tips, Costs & Best Practices provide tailored advice to help you scale your Azure environment while staying secure and managing costs in pounds sterling.
Finally, stay informed about Azure security updates and consider working with Azure security specialists or managed service providers. These partnerships can offer advanced threat detection and response capabilities, allowing you to maintain enterprise-grade security without the need for an extensive in-house team.
FAQs
How can I set up NSG rules to secure peered virtual networks without making them too permissive?
To keep your peered virtual networks secure, it's crucial to configure your Network Security Group (NSG) rules using the principle of least privilege. This means setting up only the essential inbound and outbound rules needed for communication between the networks. Steer clear of overly broad IP ranges or permitting unrestricted traffic, as these can leave your environment vulnerable to potential threats.
Make it a habit to regularly review and update your NSG rules to ensure they align with your organisation's security policies and any updates to your network architecture. Tools like Azure Monitor and traffic logs can be invaluable for spotting and addressing unusual or risky traffic patterns.
If you're looking for more tips on fine-tuning your Azure setup - whether for cost management or general best practices - there are plenty of expert resources available, especially for SMBs navigating growth on Azure.
What mistakes should I avoid when setting up NSGs for virtual network peering?
When setting up Network Security Groups (NSGs) for virtual network peering, there are several common missteps that can lead to issues. Here's what to keep an eye on:
- Overly restrictive rules: Blocking essential traffic for peering communication can disrupt connectivity. Make sure the required protocols and IP ranges are permitted to avoid interruptions.
- Assuming NSGs are automatically applied: NSGs aren't applied by default. You need to explicitly associate them with subnets or network interfaces. Without proper association, your network could be left vulnerable.
- Neglecting inbound and outbound rule reviews: It's important to regularly audit your NSG rules to ensure they meet your security and performance requirements. Outdated or misconfigured rules can lead to inefficiencies or risks.
Avoiding these mistakes can help you maintain a secure and effective peering setup. For more guidance on improving your Azure environment, dive into expert advice on cost management, architecture, and security tailored for SMBs scaling on Azure.
How can I monitor and troubleshoot Network Security Group (NSG) configurations in Azure?
To keep track of and resolve issues with NSG configurations in Azure, tools like Azure Network Watcher and NSG flow logs come in handy. These tools help you examine traffic patterns, spot misconfigurations, and address connectivity problems.
Start by activating NSG flow logs within Network Watcher. These logs record inbound and outbound traffic data, making it easier to identify unusual activity or blocked traffic. You can also use Azure Monitor to set up alerts and monitor NSG performance metrics, enabling you to tackle potential issues before they escalate.
If you're looking for more ways to streamline your Azure environment - like cutting costs or improving security - dive into expert resources designed for SMBs scaling their operations on Azure.