How to Use the Command 'az network' (with examples)
The az network
command is a powerful tool for managing Microsoft Azure network resources. Part of the Azure Command-Line Interface (CLI), this command enables users to configure, manage, and monitor various network elements in their Azure environment. Whether you want to create virtual networks, inspect network usage, or update network configurations, az network
provides a comprehensive suite of options to facilitate all these tasks. This article will illustrate how to use the az network
command for different use cases, providing practical examples along with their motivations and explanations.
Use Case 1: List Network Resources in a Region That Are Used Against a Subscription Quota
Code:
az network list-usages
Motivation:
Network resources such as Public IPs, Load Balancers, and Network Security Groups in Azure are subject to subscription quotas, which limit the number of these resources you can deploy in a region. Knowing how close you are to these quotas can help you manage resources more efficiently and avoid deployment issues caused by quota limitations. This command provides insight into the current usage of network resources, helping you plan and scale your Azure infrastructure effectively.
Explanation:
az
: Activates the Azure CLI, which facilitates commands directed towards Azure services.network
: Denotes the domain within Azure CLI focused on network resources.list-usages
: Specific sub-command that lists current usage statistics of network resources in relation to subscription quotas for a given region. There are no additional flags in this basic usage, keeping the command straightforward and easy to use.
Example Output:
The command outputs a list of network resource types in the region along with their usage statistics. Sample characteristics would be:
Name: Public IP Addresses
Current Value: 10
Limit: 20
Where the current value indicates how much of the quota is used, and the limit specifies the maximum available.
Use Case 2: List All Virtual Networks in a Subscription
Code:
az network vnet list
Motivation:
Virtual Networks (VNets) are foundational to organizing your resources within Azure. Understanding which VNets exist in your subscription allows for better management, conflict avoidance, and strategic growth of your cloud architecture. This command lists all VNets, so you can easily review and audit your network setup.
Explanation:
az
: Initiates the Azure CLI.network
: Focuses on networking operations.vnet
: Targets the virtual network commands.list
: Instructs to list all virtual networks within the subscription. This provides an overview without needing specific filters, giving the user a full breadth of VNet deployment.
Example Output:
The output details attributes of each VNet in JSON format:
{
"Name": "vnet1",
"ResourceGroup": "myResourceGroup",
"Location": "East US",
"AddressSpace": {
"AddressPrefixes": [
"10.0.0.0/16"
]
}
}
Use Case 3: Create a Virtual Network
Code:
az network vnet create --address-prefixes 10.0.0.0/16 --name vnet --resource-group group_name --subnet-name subnet --subnet-prefixes 10.0.0.0/24
Motivation:
Creating a Virtual Network is an essential step for setting up your Azure infrastructure, allowing you to manage resources within a defined network boundary. Whether launching new services or restructuring current ones, creating VNets ensures resources are securely and efficiently networked.
Explanation:
az
: Command for utilizing Azure CLI.network
: Specifically for network tasks, especially useful for virtual networks.vnet
: Command aspect focused on virtual network tasks.create
: Deployment action to establish a new VNet.--address-prefixes 10.0.0.0/16
: Sets the IP address range for this network, establishing how left digits can define subnets within.--name vnet
: States the desired name for the newly created VNet.--resource-group group_name
: Designates the resource group that will contain the VNet, helping manage and logically group resources within Azure.--subnet-name subnet
: Names the primary subnet created within the VNet.--subnet-prefixes 10.0.0.0/24
: Specifies the IP range for said subnet, accommodating 256 possible IPs, segmenting within the broader VNet address space.
Example Output:
Upon successful execution, a JSON entity defining the new VNet’s attributes appears:
{
"NewVNet": {
"Name": "vnet",
"ResourceGroup": "group_name",
"AddressSpace": {
"AddressPrefixes": [
"10.0.0.0/16"
]
},
"Subnets": [
{
"Name": "subnet",
"AddressPrefix": "10.0.0.0/24"
}
]
}
}
Use Case 4: Enable Accelerated Networking for a Network Interface Card
Code:
az network nic update --accelerated-networking true --name nic --resource-group resource_group
Motivation:
For those requiring low-latency, high-throughput network options, enabling accelerated networking can significantly enhance performance. Particularly useful for applications needing rapid data transfer and minimal network delay, this command ensures your network interface cards (NIC) are optimized for performance.
Explanation:
az
: Launches Azure CLI tool.network
: Focuses the command on network-related tasks.nic
: Specifies the sub-command to operate on Azure Network Interface Cards.update
: Allows modification of NIC attributes.--accelerated-networking true
: An option to enable accelerated networking, maximizing NIC functionality.--name nic
: Designated NIC’s name which the acceleration influences.--resource-group resource_group
: Resource grouping the NIC resides in, mapping NIC updates into Azure’s wider management systems.
Example Output:
Provided there are no errors, success output confirms the NIC’s accelerated networking feature is now enabled:
{
"NetworkInterfaceID": "nic_id",
"AcceleratedNetworkingEnabled": true
}
Conclusion:
With the help of the az network
command from Azure CLI, managing and optimizing network resources within Azure can be straightforward and highly efficient. From listing resource usages and virtual networks to creating and updating network configurations, this command covers a wide range of operations necessary for robust cloud infrastructure management. Following these illustrated examples, azure users can adeptly perform essential network tactics corresponding to their platform needs.