Azure Networking Documentation

Virtual Networks / Network Security Groups (NSGs)

Network Security Groups (NSGs)

Network Security Groups (NSGs) are a fundamental component of Azure's networking security. They act as a virtual firewall for your Azure resources to help filter network traffic. NSGs contain a list of security rules that allow or deny network traffic based on source and destination IP address, port, and protocol.

NSGs can be associated with Network Interfaces (NICs) or Subnets. When associated with a NIC, the rules apply only to the specific VM or resource connected to that NIC. When associated with a subnet, the rules apply to all resources within that subnet.

Key Concepts:

Key Features and Capabilities

How NSGs Work

When network traffic arrives at or leaves a resource in Azure, the NSG associated with its NIC or subnet is checked. The NSG evaluates its security rules in order of priority.

Rule Processing Order:

  1. The NSG checks its default rules first (highest priority).
  2. Then, it checks your custom rules in order of priority (lower number means higher priority).
  3. If a rule matches the traffic, the corresponding Allow or Deny action is applied.
  4. If no rule matches, the default rule at the end of the list (often a 'Deny All') is applied.

Inbound vs. Outbound Security Rules:

Common NSG Rule Examples

Allow Inbound SSH Traffic

This rule allows SSH traffic (TCP port 22) from any source to your virtual machines.

Rule Details:

  • Priority: 100
  • Source: Any
  • Source Port Ranges: *
  • Destination: Any
  • Destination Port Ranges: 22
  • Protocol: TCP
  • Action: Allow
  • Name: AllowSSH

Description: Allows inbound SSH connections to VMs.

Allow Outbound HTTP/HTTPS Traffic

This rule allows your VMs to access the internet for web browsing and updates.

Rule Details:

  • Priority: 200
  • Source: Any
  • Source Port Ranges: *
  • Destination: Internet
  • Destination Port Ranges: 80, 443
  • Protocol: TCP
  • Action: Allow
  • Name: AllowWebOutbound

Description: Permits outbound HTTP and HTTPS traffic.

Deny Inbound RDP Traffic

This rule explicitly denies RDP traffic (TCP port 3389) from any source, overriding any other 'Allow' rule that might exist for this port.

Rule Details:

  • Priority: 90
  • Source: Any
  • Source Port Ranges: *
  • Destination: Any
  • Destination Port Ranges: 3389
  • Protocol: TCP
  • Action: Deny
  • Name: DenyRDP

Description: Explicitly blocks inbound RDP connections.

Best Practices for NSGs

Related Resources