Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

How to reserve an Azure Public IP Range

·863 words·5 mins· 100 views · 5 likes ·
Azure CLI Azure Cloud Shell Azure PowerShell Connect-AzAccount

Hi, today I want to talk to you about the Azure public IP prefix. This functionality allows us to have a range of continuous public IPs and thereby simplify the administration of our public endpoints in Azure. Therefore, in this post, I will show you how to create a public IP prefix using PowerShell and Azure CLI.

Constraints at the time of publication of this article:

  • You can create a prefix of up to 16 IP addresses or a /28
  • You cannot change the range, once created.
  • Only static public IP addresses created with the Standard SKU can be assigned from the prefix’s range.
Prerequisites>

Prerequisites #

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You created a Resource Group for these resources and the new ones deployed in this tutorial will join that group. If you want to know how to create a Resource Group, check out this  link.
Azure PowerShell Workaround>

Azure PowerShell Workaround #

If you want to know how to install the PowerShell Azure module on your machine, check out this link. The simplest way to get started is to sign in interactively at the command line.

Connect-AzAccount

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Get-AzSubscription
Select-AzSubscription -Subscription "My Subscription"

Once you set your default subscription, you’re ready to start.

Set the variables>

Set the variables #

Here, we define the characteristics of our environment and the resource’s properties.

$ResourceGroupName = "RG-DEMO-NE"
$location = "northeurope"
$prefixName = "PIP-Range-NE"
Create a public IP address prefix>

Create a public IP address prefix #

To create a public IP address prefix, you should use the New-AzPublicIpPrefix cmdlet with the following syntax.

$pipRange = New-AzPublicIpPrefix `
    -Name $prefixName `
    -ResourceGroupName $ResourceGroupName `
    -PrefixLength 28 `
    -Location $location `
    -IpAddressVersion IPv4 `
    -Sku Standard
Azure IP public prefix
>

Azure IP public prefix
#

Create a public IP using the Azure public prefix>

Create a public IP using the Azure public prefix #

To create a public IP within the range created in the previous step, you should use the New-AzPublicIpAddress cmdlet with the following syntax.

$publicIpName = "pip-demo"

New-AzPublicIpAddress `
    -Name $publicIpName `
    -ResourceGroupName $ResourceGroupName `
    -Location $location `
    -PublicIpPrefix $pipRange `
    -AllocationMethod Static `
    -Sku Standard
New-AzPublicIpAddress
>

New-AzPublicIpAddress
#

As you can see in the following screenshot, we are now using an IP of the 16 reserved IPs in the range.

Azure IP public prefix
>

Azure IP public prefix
#

Remove a used public IP from the range>

Remove a used public IP from the range #

To remove a used public IP from its range, you must use the Remove-AzPublicIpAddress cmdlet with the following syntax. Remember that this IP should not be associated with any existing resource.

Remove-AzPublicIpAddress `
    -Name $publicIpName `
    -ResourceGroupName $ResourceGroupName `
    -Force
Remove an Azure public IP prefix>

Remove an Azure public IP prefix #

If you want to remove a public IP prefix, use the Remove-AzPublicIpPrefix cmdlet with the following syntax. Remember that all IPs in the range should not be associated with azure resources.

Remove-AzPublicIpPrefix `
    -Name $pipRange `
    -ResourceGroupName $ResourceGroupName `
    -Force
Azure CLI Workaround>

Azure CLI Workaround #

In this case, we will use Azure Cloud Shell, a browser-based shell built into Azure Portal. This allows us to use the Azure command-line tools (Azure CLI and Azure PowerShell) directly from a browser. If you want to know more about Azure Cloud Shell, check out this link.

First, declare the variables of the resource group and define the name of the public IP prefix that will be created in the next step.

resourceGroupName="RG-DEMO-NE"
location="northeurope"
prefixName="PIP-Range-NE"
Create a public IP address prefix>

Create a public IP address prefix #

To create a public IP address prefix, you should use the following command.

az network public-ip prefix create \
--name $prefixName \
--resource-group $ResourceGroupName \
--location $location \
--length 28 \
--version IPv4

Azure IP public prefix

Create a public IP from Azure public prefix>

Create a public IP from Azure public prefix #

To create a public IP within the range created in the previous step, you should use the following command.

publicIpName="pip-demo-NE"

az network public-ip create \
--name $publicIpName \
--resource-group $ResourceGroupName \
--location $location \
--public-ip-prefix $prefixName \
--allocation-method Static \
--sku standard
Azure IP public prefix
>

Azure IP public prefix
#

Remove a used public IP from the range>

Remove a used public IP from the range #

To remove a used public IP from its range, you must use the following syntax. Remember that this IP should not be associated with any existing resource.

az network public-ip delete \
--name $publicIpName \
--resource-group $ResourceGroupName
Remove an Azure public IP prefix>

Remove an Azure public IP prefix #

If you want to remove a public IP prefix, use the following command. Remember that all IPs in the range should not be associated with azure resources.

az network public-ip prefix delete \
--name $prefixName \
--resource-group $ResourceGroupName

Thanks for reading my post. I hope you find it useful.

If you want to know more about Azure Public IP address prefix, check out this link.