Skip to content

Latest commit

 

History

History
321 lines (246 loc) · 11.6 KB

File metadata and controls

321 lines (246 loc) · 11.6 KB
title Quickstart: Create a public IP address prefix - PowerShell
titleSuffix Azure Virtual Network
description Learn how to create a public IP address prefix using PowerShell.
services virtual-network
author mbender-ms
ms.author mbender
ms.service azure-virtual-network
ms.subservice ip-services
ms.topic quickstart
ms.date 01/09/2025
ms.custom mode-api, devx-track-azurepowershell

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 an account for free.
  • Azure PowerShell installed locally or Azure Cloud Shell

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 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 westus2 location.

$rg =@{
    Name = 'QuickStartCreateIPPrefix-rg'
    Location = 'westus2'
}
New-AzResourceGroup @rg

Create a public IP address prefix

In this section, you create a zone redundant and 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 westus2 location.

IPv4

To create a IPv4 Standard 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'
    Sku - 'standard'
    Location = 'westus2'
    PrefixLength = '28'
    IpAddressVersion = 'IPv4'
    Zone = 1,2,3
}
New-AzPublicIpPrefix @ipv4

To create a IPv4 Standard v2 public IP prefix, enter IPv4 in the -IpAddressVersion parameter. All Standardv2 IPv4 public IP prefixes must be zone-redundant, so enter 1,2,3 in the -Zone parameter.

$ipv4 =@{
    Name = 'myPublicIpPrefix'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standardv2'
    Location = 'westus2'
    PrefixLength = '28'
    IpAddressVersion = 'IPv4'
    Zone = 1,2,3
}
New-AzPublicIpPrefix @ipv4

To create a IPv4 public IP prefix, enter IPv4 in the -IpAddressVersion parameter. Enter 2 in the -Zone parameter to create a zonal IP prefix in zone 2.

$ipv4 =@{
    Name = 'myPublicIpPrefix-zonal'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standard'
    Location = 'westus2'
    PrefixLength '28'
    IpAddressVersion = 'IPv4'
    Zone = 2
}
New-AzPublicIpPrefix @ipv4

Note

The above options for zones are only valid selections in regions with Availability Zones.

To create a IPv4 public IP prefix, enter IPv4 in the -IpAddressVersion parameter. Remove the -Zone parameter to create a non-zonal IP prefix.

$ipv4 =@{
    Name = 'myPublicIpPrefix-nozone'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standard'
    Location = 'westus'
    PrefixLength '28'
    IpAddressVersion = 'IPv4'
}
New-AzPublicIpPrefix @ipv4

The removal of the -Zone parameter in the command is valid in all regions, but will lead to the creation of a zone-redundant IP prefix in regions with availability zones. The removal of the -Zone parameter is the default selection for standard public IP addresses in regions without Availability Zones.

To create a IPv4 public IP prefix with routing preference Internet, create an IpTag with an ipTagType 'Routing Preference' and Tag 'Internet'.

$tagproperty = @{
IpTagType = 'RoutingPreference'
Tag = 'Internet'
}
$routingprefinternettag = New-Object -TypeName Microsoft.Azure.Commands.Network.Models.PSPublicIpPrefixTag -Property $tagproperty 
$ipv4 =@{
    Name = 'myPublicIpPrefix-routingprefinternet'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Location = 'westus2'
    PrefixLength '28'
    IpAddressVersion = 'IPv4'
    IpTag = $routingprefinternettag
}
New-AzPublicIpPrefix @ipv4

IPv6

To create a Standard IPv6 public IP prefix, enter IPv6 in the -IpAddressVersion parameter. To create a zone redundant Standard IPv6 prefix, enter 1,2,3 in the -Zone parameter.

$ipv6 =@{
    Name = 'myPublicIpPrefix'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standard'
    Location = 'westus2'
    PrefixLength = '124'
    IpAddressVersion = 'IPv6'
    Zone = 1,2,3
}
New-AzPublicIpPrefix @ipv6

To create a Standardv2 IPv6 public IP prefix, enter IPv6 in the -IpAddressVersion parameter. All Standardv2 IPv6 public IP prefixes must be zone-redundant, so enter 1,2,3 in the -Zone parameter.

$ipv6 =@{
    Name = 'myPublicIpPrefix'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standard'
    Location = 'westus2'
    PrefixLength = '124'
    IpAddressVersion = 'IPv6'
    Zone = 1,2,3
}
New-AzPublicIpPrefix @ipv6

To create a IPv6 public IP prefix, enter IPv6 in the -IpAddressVersion parameter. Enter 2 in the -Zone parameter to create a zonal IP prefix in zone 2.

$ipv6 =@{
    Name = 'myPublicIpPrefix-zonal'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standard'
    Location = 'westus2'
    PrefixLength = '124'
    IpAddressVersion = 'IPv6'
    Zone = 2
}
New-AzPublicIpPrefix @ipv6

Note

The above options for zones are only valid selections in regions with Availability Zones.

To create a IPv6 public IP prefix, enter IPv6 in the -IpAddressVersion parameter. Remove the -Zone parameter to create a non-zonal IP prefix.

$ipv6 =@{
    Name = 'myPublicIpPrefix-nozone'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Sku - 'standard'
    Location = 'westus'
    PrefixLength = '124'
    IpAddressVersion = 'IPv6'
}
New-AzPublicIpPrefix @ipv6

The removal of the -Zone parameter in the command is valid in all regions, but will lead to the creation of a zone-redundant IP prefix in regions with availabily zones. The removal of the -Zone parameter is the default selection for standard public IP addresses in regions without Availability Zones.


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.

Note

To derive an IP address from a Standard v2 Prefix, the process is identical to the commands below, with the exception of the Sku parameter (which must be set to Standardv2)

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 = 'westus2'
    Sku = 'Standard'
    Tier = 'Regional'
    AllocationMethod = 'Static'
    IpAddressVersion = 'IPv4'
    PublicIpPrefix = $prefix
}
New-AzPublicIpAddress @ipv4

To create a IPv6 public IP address, enter IPv6 in the -IpAddressVersion parameter.

$pf =@{
    Name = 'myPublicIpPrefix'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
}
$prefix = Get-AzPublicIpPrefix @pf

$ipv6 =@{
    Name = 'myPublicIpAddress'
    ResourceGroupName = 'QuickStartCreateIPPrefix-rg'
    Location = 'westus2'
    Sku = 'Standard'
    Tier = 'Regional'
    AllocationMethod = 'Static'
    IpAddressVersion = 'IPv6'
    PublicIpPrefix = $prefix
}
New-AzPublicIpAddress @ipv6

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:

[!div class="nextstepaction"] Create public IP using PowerShell