Create a network security group and open one port

Azure Portal, Hands On10 minutesFreeSteps checked 23 October 2026By Cloud Hands On

In this task you'll create a network security group rule.

A network security group (NSG) is a list of allow and deny rules for network traffic, like a simple firewall. You attach it to a subnet (or a single VM's network card), and every packet in or out is checked against the rules.

Rules are checked in order of priority, lowest number first, and the first match wins. Every NSG also has default rules at the bottom: traffic inside the network is allowed, and everything else coming in from the internet is denied.

Example. SS Kaiser's web subnet has an NSG that allows HTTPS (port 443) from anywhere and SSH (port 22) only from the head office's address. Everything else from the internet hits the default deny rule.

Before you start

You need: Network Contributor or Contributor. Time: 10 minutes.

Where to look

  1. Home
  2. Network security groups
  3. + Create

Steps

  1. Open Network security groups, select + Create, choose rg-portal-practice, name it nsg-web, pick the same region as your network and create it.
  2. Open nsg-web and select Inbound security rules. Read the three default rules at the bottom.
  3. Select + Add. Leave Source as Any, set Destination port ranges to 443, Protocol to TCP and Action to Allow.
  4. Give it priority 100 and the name allow-https, then select Add.
  5. Select Subnets, then + Associate. Choose vnet-practice and snet-web, then OK.The rules now apply to everything in that subnet.

Commands

# Create the NSG and an HTTPS rule
az network nsg create --resource-group rg-portal-practice --name nsg-web

az network nsg rule create --resource-group rg-portal-practice --nsg-name nsg-web \
  --name allow-https --priority 100 --direction Inbound --access Allow \
  --protocol Tcp --destination-port-ranges 443

# Attach it to the subnet
az network vnet subnet update --resource-group rg-portal-practice \
  --vnet-name vnet-practice --name snet-web --network-security-group nsg-web

Watch out for

Cost
Network security groups are free.
Security
Never allow management ports such as 22 (SSH) or 3389 (Remote Desktop) from Any. Limit them to known addresses, or use Azure Bastion.
Common mistakes
Putting a broad deny rule at a lower number than the allow you need, so the allow never runs. Forgetting that an NSG on the subnet and another on the VM's network card must both allow the traffic.

Clean up

  1. Network security groups
  2. nsg-web
  3. Subnets

Keep it for the next task. To remove it, first dissociate it from the subnet, then delete the NSG, or delete the resource group at the end of this section.

Words to know

Priority
A number from 100 to 4096. Lower numbers are checked first.
Service tag
A name for a group of addresses, such as Internet or VirtualNetwork, so you don't have to type ranges.
Default rules
Built-in rules with priorities from 65000 that you can override but not delete.

Tick off each step and track your progress in the guide.

Open this task in Azure Portal, Hands On

Keep going