How to use the command 'az network' (with examples)

How to use the command 'az network' (with examples)

The az network command allows users to manage Azure Network resources. This command is part of the azure-cli, also known as az. It provides a set of functionalities to list, create, and update network resources within a subscription. In this article, we will explore several examples of using the az network command.

Use case 1: List network resources in a region that are used against a subscription quota.

Code:

az network list-usages

Motivation: This example is useful when you need to check the current resource utilization against your subscription quota in a specific region. By listing the network usages, you can identify any potential resource limitations and manage your network resources accordingly.

Explanation: The command az network list-usages lists the network resources used in a region against a subscription quota. It retrieves information such as the resource name, unit, current usage, and limit.

Example output:

[
    {
        "name": "networkSecurityGroups",
        "unit": "Count",
        "currentValue": 10,
        "limit": 100
    },
    {
        "name": "virtualNetworkGateways",
        "unit": "Count",
        "currentValue": 2,
        "limit": 50
    }
]

Use case 2: List all virtual networks in a subscription.

Code:

az network vnet list

Motivation: This example is useful when you want to view all the virtual networks within your subscription. By listing the virtual networks, you can easily get an overview of your network infrastructure and manage them accordingly.

Explanation: The command az network vnet list retrieves a list of all the virtual networks in a subscription. It provides detailed information such as the virtual network name, IP address range, and subnet details.

Example output:

[
    {
        "name": "vnet1",
        "addressSpace": {
            "addressPrefixes": [
                "10.0.0.0/16"
            ]
        },
        "subnets": [
            {
                "name": "subnet1",
                "addressPrefix": "10.0.0.0/24"
            }
        ]
    },
    {
        "name": "vnet2",
        "addressSpace": {
            "addressPrefixes": [
                "192.168.0.0/16"
            ]
        },
        "subnets": [
            {
                "name": "subnet2",
                "addressPrefix": "192.168.0.0/24"
            }
        ]
    }
]

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: This example is useful when you need to create a virtual network with a specific configuration. By using this command, you can define the desired address prefixes, name, and subnet details for the virtual network. This allows you to customize your network infrastructure according to your requirements.

Explanation: The command az network vnet create creates a virtual network with the specified configuration. The --address-prefixes option defines the IP address range for the virtual network, while the --name option specifies the name of the virtual network. The --resource_group option indicates the resource group where the virtual network should be created. Finally, the --subnet-name and --subnet-prefixes options define the subnet name and its corresponding IP address range.

Example output:

{
    "newVNet": {
        "name": "vnet",
        "id": "/subscriptions/<subscription_id>/resourceGroups/group_name/providers/Microsoft.Network/virtualNetworks/vnet",
        "location": "westus",
        "addressSpace": {
            "addressPrefixes": [
                "10.0.0.0/16"
            ]
        },
        "subnet": {
            "name": "subnet",
            "id": "/subscriptions/<subscription_id>/resourceGroups/group_name/providers/Microsoft.Network/virtualNetworks/vnet/subnets/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: This example is useful when you want to enable accelerated networking for a network interface card (NIC). Accelerated networking improves the performance and latency of virtual machines by offloading the network traffic processing to the hardware. By enabling this feature, you can optimize your network connectivity and enhance the overall performance of your virtual machines.

Explanation: The command az network nic update updates the settings of a network interface card. The --accelerated-networking option is set to true in order to enable accelerated networking for the NIC. The --name option specifies the name of the NIC, and the --resource-group option indicates the resource group where the NIC is located.

Example output:

{
    "etag": "W/\"<etag>\"",
    "id": "/subscriptions/<subscription_id>/resourceGroups/resource_group/providers/Microsoft.Network/networkInterfaces/nic",
    "location": "westus",
    "name": "nic",
    "type": "Microsoft.Network/networkInterfaces",
    ...
    "enableAcceleratedNetworking": true,
    ...
}

Conclusion:

The az network command provides a powerful set of functionalities to manage Azure Network resources. By effectively using this command, you can list network resources, create virtual networks, and update network interface cards. These examples illustrate various use cases and showcase the flexibility and versatility of the az network command.

Related Posts

Initializing a Mercurial Repository (with examples)

Initializing a Mercurial Repository (with examples)

1: Initialize a new repository in the current directory The initial use case for the hg init command is to create a new Mercurial repository in the current working directory.

Read More
How to use the command 'a2query' (with examples)

How to use the command 'a2query' (with examples)

The ‘a2query’ command is used to retrieve runtime configuration from Apache on Debian-based operating systems.

Read More
How to use the command fc-match (with examples)

How to use the command fc-match (with examples)

The fc-match command is used to match available fonts on a system.

Read More