1 minute reading time (175 words)

Create Network Security Group (NSG) using Azure CLI

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

Create NSG using az network nsg create 

# 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 
 

Associate the new NSG to a subnet

# 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/nsg

Azure CLI - az network vnet subnet
https://docs.microsoft.com/en-us/cli/azure/network/vnet/subnet

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Saturday, 23 September 2023
You can help support this website by buying me a coffee!
Buy Me A Coffee