Network Security Groups (NSGs)

Network Security Groups (NSGs) are a fundamental component of Azure networking, enabling you to filter network traffic to and from Azure resources in an Azure virtual network (VNet), subnets, and individual network interfaces (NICs).

What are Network Security Groups?

An NSG contains a list of security rules that allow or deny network traffic. These rules are evaluated based on the priority number. The lower the priority number, the higher the priority of the rule. NSGs can be associated with:

If an NSG is associated with both a subnet and a NIC, the rules from both are applied. The order of evaluation is:

  1. Effective security rules on the NIC
  2. Effective security rules on the subnet

Security Rule Properties

Each security rule has the following properties:

Default Security Rules

When you create an NSG, it automatically includes the following default rules, which cannot be deleted but can be overridden by custom rules with higher priority:

Creating and Managing NSGs

You can create and manage NSGs using the Azure portal, Azure CLI, Azure PowerShell, or ARM templates.

Example: Allow HTTP traffic to a subnet

To allow inbound HTTP traffic (port 80) to a specific subnet, you would create a new inbound security rule:

Name: AllowHTTP
Priority: 100
Source: Any
Source port ranges: *
Destination: Any
Destination port ranges: 80
Protocol: TCP
Direction: Inbound
Action: Allow
                

Best Practices

Learn More: For detailed information on creating and configuring NSGs, please refer to the official Azure NSG documentation.