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.
Prerequisites
- An Azure subscription. If you don't have one, create a free account before you begin.
- Appropriate permissions to create network resources within your subscription.
Method 1: Using the Azure portal
The Azure portal provides a user-friendly graphical interface for creating and managing Azure resources.
-
Sign in to the Azure portal.
-
In the search bar at the top, type "Network security groups" and select "Network security groups" from the search results.
-
On the "Network security groups" page, click + Create.
-
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.
-
Click Review + create.
-
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.
az network nsg create --resource-group myResourceGroup --name myNsg --location eastus
Explanation:
az network nsg create: The command to create a network security group.--resource-group myResourceGroup: Specifies the resource group where the NSG will be created.--name myNsg: Sets the name of the network security group.--location eastus: Defines the Azure region for the NSG.
Method 3: Using Azure PowerShell
Azure PowerShell provides a robust scripting environment for managing Azure resources.
New-AzNetworkSecurityGroup -Name "myNsg" -ResourceGroupName "myResourceGroup" -Location "East US"
Explanation:
New-AzNetworkSecurityGroup: The cmdlet to create a new network security group.-Name "myNsg": Specifies the name of the NSG.-ResourceGroupName "myResourceGroup": Assigns the NSG to a resource group.-Location "East US": Sets the Azure region for the NSG.
Next Steps
After creating your NSG, you'll want to configure security rules to control traffic. For more information, see: