Azure CLI Azure Cloud Shell Azure PowerShell Connect-AzAccount Get-AzSubscription Microsoft Microsoft Azure New-AzPublicIpAddress New-AzPublicIpPrefix Remove-AzPublicIpAddress Remove-AzPublicIpPrefix Select-AzSubscription Virtual networks
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.
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.
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:
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.
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.
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.
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