MSDN Documentation

Create a Network Security Group (NSG)

This article guides you through the process of creating a Network Security Group (NSG) using the Azure portal, Azure CLI, and Azure PowerShell. NSGs are a fundamental component for network security in Azure, allowing you to filter network traffic to and from Azure resources in an Azure virtual network, subnets, and individual network interfaces.

Note: You can create an NSG either as a standalone resource or associate it with a subnet or network interface during resource creation. This guide focuses on creating a standalone NSG.

Prerequisites

Method 1: Using the Azure portal

The Azure portal provides a user-friendly graphical interface for creating and managing Azure resources.

  1. Sign in to the Azure portal.

  2. In the search bar at the top, type "Network security groups" and select "Network security groups" from the search results.

  3. On the "Network security groups" page, click + Create.

  4. On the "Basics" tab of the "Create network security group" page, configure the following settings:

    • Subscription: Select your Azure subscription.
    • Resource group: Select an existing resource group or click "Create new" to create a new one.
    • Name: Enter a unique name for your network security group (e.g., my-nsg-example).
    • Region: Select the Azure region where you want to deploy the NSG. Choose a region that is close to your virtual network or resources.
  5. Click Review + create.

  6. After validation passes, review the summary and click Create.

Once the deployment is complete, you can find your new NSG in the list of Network security groups. You can then proceed to associate it with a subnet or network interface and configure security rules.

Method 2: Using Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources programmatically. To use the Azure CLI, ensure you have it installed and logged in to your Azure account.

Azure CLI Copy
az network nsg create --resource-group myResourceGroup --name myNsg --location eastus

Explanation:

Method 3: Using Azure PowerShell

Azure PowerShell provides a robust scripting environment for managing Azure resources.

Azure PowerShell Copy
New-AzNetworkSecurityGroup -Name "myNsg" -ResourceGroupName "myResourceGroup" -Location "East US"

Explanation:

Next Steps

After creating your NSG, you'll want to configure security rules to control traffic. For more information, see: