How to create a Network Security Group (NSG) using Azure CLI
In this example, we will create an NSG for the subnet rather than attaching individual NSGs to each VM.
The virtual machine has been created without an NSG by specifying an empty variable --nsg""
We are using an existing resource group and vnet
Resource group: prod-ukw-core-rg
Vnet: prod-ukw-core-vnet
# define nsg variables NsgName=prod-ukw-core-vnet-nsg RGroup=prod-ukw-core-rg Location=ukwest az network nsg create \ --name $NsgName \ --resource-group $RGroup \ --location $Location
# define subnet and nsg variables RGroup=prod-ukw-core-rg Subnet=subnet01 Vnet=prod-ukw-core-vnet Nsg=prod-ukw-core-vnet-nsg az network vnet subnet update \ -g $RGroup \ -n $Subnet \ --vnet-name $Vnet \ --network-security-group $Nsg
References:
Azure CLI - az network nsg
https://docs.microsoft.com/en-us/cli/azure/network/nsgAzure CLI - az network vnet subnet
by Author
https://docs.microsoft.com/en-us/cli/azure/network/vnet/subnet
Comments