Azure Documentation

Network Security Groups (NSGs)

Network Security Groups (NSGs) are a fundamental component of Azure's network security infrastructure. They allow you to filter network traffic to and from Azure resources in an Azure virtual network (VNet), subscription, resource group, or individual resource.

What are NSGs?

An NSG acts as a virtual firewall for your network resources. It contains a list of security rules that allow or deny network traffic based on criteria such as:

Key Components of an NSG

Default Security Rules

When you create an NSG, it comes with a set of default rules that cannot be deleted, only modified. These are:

Creating and Managing NSGs

Using the Azure Portal

You can create and manage NSGs through the Azure portal:

  1. Navigate to the Azure portal.
  2. Search for "Network Security Groups" and select it.
  3. Click "+ Create" to create a new NSG.
  4. Fill in the required details (Subscription, Resource group, Name, Region).
  5. Once created, you can configure inbound and outbound security rules.

Using Azure CLI

Here's an example of how to create an NSG and add a rule using the Azure CLI:

# Create a new NSG
az network nsg create --resource-group myResourceGroup --name myNsg --location eastus

# Add an inbound security rule to allow SSH traffic (port 22)
az network nsg rule create --resource-group myResourceGroup --nsg-name myNsg --name AllowSSH --priority 300 --protocol Tcp --dest-port-range 22 --access Allow --direction Inbound

# Associate NSG with a subnet
az network vnet subnet update --resource-group myResourceGroup --vnet-name myVnet --name mySubnet --network-security-group myNsg

            

Best Practices

Important: NSGs do not filter traffic between subnets by default. For inter-subnet traffic filtering, consider Azure Firewall or User Defined Routes (UDRs) in conjunction with NSGs.
Pro Tip: For more granular control and centralized management of network security across your Azure environment, explore Azure Firewall.