Quickstart: Create a public IP address prefix using the Azure CLI

Learn about a public IP address prefix and how to create, change, and delete one. A public IP address prefix is a contiguous range of standard SKU public IP addresses.

When you create a public IP address resource, you can assign a static public IP address from the prefix and associate the address to virtual machines, load balancers, or other resources. For more information, see Public IP address prefix overview.

If you don't have an Azure subscription, create an Azure free account before you begin.

Prerequisites

  • This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.

Create a resource group

An Azure resource group is a logical container into which Azure resources are deployed and managed.

Create a resource group with az group create named QuickStartCreateIPPrefix-rg in the eastus2 location.

  az group create \
    --name QuickStartCreateIPPrefix-rg \
    --location eastus2

Create a public IP address prefix

In this section, you create a zone redundant, zonal, and non-zonal public IP prefix using Azure PowerShell.

The prefixes in the examples are:

  • IPv4 - /28 (16 addresses)

  • IPv6 - /124 (16 addresses)

For more information on available prefix sizes, see Prefix sizes.

Create a public IP prefix with az network public-ip prefix create named myPublicIpPrefix in the eastus2 location.

IPv4

To create a IPv4 public IP prefix, enter IPv4 in the --version parameter. To create a zone redundant IPv4 prefix, enter 1,2,3 in the --zone parameter.

  az network public-ip prefix create \
    --length 28 \
    --name myPublicIpPrefix \
    --resource-group QuickStartCreateIPPrefix-rg \
    --location eastus2 \
    --version IPv4 \
    --zone 1 2 3

To create a IPv4 public IP prefix with routing preference Internet, enter RoutingPreference=Internet in the --ip-tags parameter.

  az network public-ip prefix create \
    --length 28 \
    --name myPublicIpPrefix-rpinternet \
    --resource-group QuickStartCreateIPPrefix-rg \
    --location eastus2 \
    --version IPv4
    --iptags 'RoutingPreference=Internet'

IPv6

To create a IPv4 public IP prefix, enter IPv6 in the --version parameter. To create a zone redundant IPv6 prefix, enter 1,2,3 in the --zone parameter.

  az network public-ip prefix create \
    --length 124 \
    --name myPublicIpPrefix \
    --resource-group QuickStartCreateIPPrefix-rg \
    --location eastus2 \
    --version IPv6 \
    --zone 1 2 3

Create a static public IP address from a prefix

Once you create a prefix, you must create static IP addresses from the prefix. In this section, you create a static IP address from the prefix you created earlier.

Create a public IP address with az network public-ip create in the myPublicIpPrefix prefix.

To create a IPv4 public IP address, enter IPv4 in the --version parameter.

  az network public-ip create \
    --name myPublicIP \
    --resource-group QuickStartCreateIPPrefix-rg \
    --allocation-method Static \
    --public-ip-prefix myPublicIpPrefix \
    --sku Standard \
    --version IPv4

Note

Only static public IP addresses created with the standard SKU can be assigned from the prefix's range. To learn more about public IP address SKUs, see public IP address.

Delete a prefix

In this section, you learn how to delete a prefix.

To delete a public IP prefix, use az network public-ip prefix delete.

  az network public-ip prefix delete \
    --name myPublicIpPrefix \
    --resource-group QuickStartCreateIPPrefix-rg

Note

If addresses within the prefix are associated to public IP address resources, you must first delete the public IP address resources. See delete a public IP address.

Clean up resources

In this article, you created a public IP prefix and a public IP from that prefix.

When you're done with the public IP prefix, delete the resource group and all of the resources it contains with az group delete.

  az group delete \
    --name QuickStartCreateIPPrefix-rg

Next steps

Advance to the next article to learn how to create a public IP prefix using Azure PowerShell: