Quickstart: Create a public IP address prefix using PowerShell
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.
Prerequisites
- An Azure account with an active subscription. Create a trial subscription.
- Azure PowerShell installed locally.
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run Get-Module -ListAvailable Az
to find the installed version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount -Environment AzureChinaCloud
to create a connection with Azure.
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 New-AzResourceGroup named QuickStartCreateIPPrefix-rg in the chinaeast2 location.
$rg =@{
Name = 'QuickStartCreateIPPrefix-rg'
Location = 'chinanorth3'
}
New-AzResourceGroup @rg
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 New-AzPublicIpPrefix named myPublicIpPrefix in the chinanorth3 location.
IPv4
To create a IPv4 public IP prefix, enter IPv4 in the -IpAddressVersion
parameter. To create a zone redundant IPv4 prefix, enter 1,2,3 in the -Zone
parameter.
$ipv4 =@{
Name = 'myPublicIpPrefix'
ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
Location = 'chinanorth3'
PrefixLength = '28'
IpAddressVersion = 'IPv4'
Zone = 1,2,3
}
New-AzPublicIpPrefix @ipv4
IPv6
To create a IPv4 public IP prefix, enter IPv6 in the -IpAddressVersion
parameter. To create a zone redundant IPv6 prefix, enter 1,2,3 in the -Zone
parameter.
$ipv6 =@{
Name = 'myPublicIpPrefix'
ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
Location = 'chinanorth3'
PrefixLength = '124'
IpAddressVersion = 'IPv6'
Zone = 1,2,3
}
New-AzPublicIpPrefix @ipv6
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 New-AzPublicIpAddress in the myPublicIpPrefix prefix.
To create a IPv4 public IP address, enter IPv4 in the -IpAddressVersion
parameter.
$pf =@{
Name = 'myPublicIpPrefix'
ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
}
$prefix = Get-AzPublicIpPrefix @pf
$ipv4 =@{
Name = 'myPublicIpAddress'
ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
Location = 'chinanorth3'
Sku = 'Standard'
Tier = 'Regional'
AllocationMethod = 'Static'
IpAddressVersion = 'IPv4'
PublicIpPrefix = $prefix
}
New-AzPublicIpAddress @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 Remove-AzPublicIpPrefix.
$pr =@{
Name = 'myPublicIpPrefix'
ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
}
Remove-AzPublicIpPrefix @pr
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:
Remove-AzResourceGroup -ResourceGroupName 'QuickStartCreateIPPrefix-rg'
Next steps
Advance to the next article to learn how to create a public IP prefix using the Azure CLI: