创建、更改或删除公共 IP 前缀Create, change, or delete a public IP prefix

了解公共 IP 前缀,以及如何创建、更改和删除此类前缀。Learn about a public IP prefix and how to create, change, and delete one. 公共 IP 前缀是基于你指定的公共 IP 地址数的连续地址范围。A public IP prefix is a contiguous range of addresses based on the number of public IP addresses you specify. 地址会分配给你的订阅。The addresses are assigned to your subscription. 创建公共 IP 地址资源时,可以从前缀分配一个静态公共 IP 地址,并将该地址关联到虚拟机、负载均衡器或其他资源,以启用 Internet 连接。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, to enable internet connectivity. 如果你不熟悉公共 IP 前缀,请参阅公共 IP 前缀概述If you're not familiar with public IP prefixes, see Public IP prefix overview

准备阶段Before you begin

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

在完成本文任何部分中的步骤之前,请完成以下任务:Complete the following tasks before completing steps in any section of this article:

  • 如果还没有 Azure 帐户,请注册试用帐户If you don't already have an Azure account, sign up for a trial account.
  • 如果使用门户,请打开 https://portal.azure.cn ,并使用 Azure 帐户登录。If using the portal, open https://portal.azure.cn, and log in with your Azure account.
  • 如果使用 PowerShell 命令来完成本文中的任务,请从计算机运行 PowerShell。If using PowerShell commands to complete tasks in this article, by running PowerShell from your computer. 本教程需要 Azure PowerShell 模块 1.0.0 或更高版本。This tutorial requires the Azure PowerShell module version 1.0.0 or later. 运行 Get-Module -ListAvailable Az 查找已安装的版本。Run Get-Module -ListAvailable Az to find the installed version. 如果需要进行升级,请参阅 Install Azure PowerShell module(安装 Azure PowerShell 模块)。If you need to upgrade, see Install Azure PowerShell module. 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount -Environment AzureChinaCloud 来创建与 Azure 的连接。If you are running PowerShell locally, you also need to run Connect-AzAccount -Environment AzureChinaCloud to create a connection with Azure.
  • 如果使用 Azure 命令行界面 (CLI) 命令来完成本文中的任务,请从计算机运行 CLI。If using Azure Command-line interface (CLI) commands to complete tasks in this article, by running the CLI from your computer. 本教程需要 Azure CLI 2.0.41 或更高版本。This tutorial requires the Azure CLI version 2.0.41 or later. 运行 az --version 查找已安装的版本。Run az --version to find the installed version. 如果需要进行安装或升级,请参阅安装 Azure CLI 2.0If you need to install or upgrade, see Install Azure CLI 2.0. 如果在本地运行 Azure CLI,则还需运行 az login 以创建与 Azure 的连接。If you are running the Azure CLI locally, you also need to run az login to create a connection with Azure.

登录或连接到 Azure 所用的帐户必须分配有网络参与者角色或者分配有可执行权限中列出的适当操作的自定义角色The account you log into, or connect to Azure with, must be assigned to the network contributor role or to a custom role that is assigned the appropriate actions listed in Permissions.

公共 IP 前缀要收费。Public IP prefixes have a charge. 有关详细信息,请参阅定价For details, see pricing.

创建公共 IP 前缀Create a public IP prefix

  1. 在门户左上角的顶部选择“+ 创建资源”****。At the top, left corner of the portal, select + Create a resource.

  2. 在“搜索市场”** 框中输入“公共 IP 前缀”**。Enter Public IP Prefix in the Search the Marketplace box. 当“公共 IP 前缀”**** 出现在搜索结果中时,请选择它。When Public IP Prefix appears in the search results, select it.

  3. 在“公共 IP 前缀”**** 下,选择“创建”****。Under Public IP prefix, select Create.

  4. 在“创建公共 IP 前缀”**** 下为以下设置输入或选择值,然后选择“创建”****:Enter, or select values for the following settings, under Create public IP prefix, then select Create:

    设置Setting 必需?Required? 详细信息Details
    订阅Subscription Yes 必须与要将公共 IP 地址关联到的资源位于同一订阅中。Must exist in the same subscription as the resource you want to associate the public IP address to.
    资源组Resource group Yes 可与要将公共 IP 地址关联到的资源位于相同或不同的资源组中。Can exist in the same, or different, resource group as the resource you want to associate the public IP address to.
    名称Name Yes 名称在所选资源组中必须唯一。The name must be unique within the resource group you select.
    区域Region Yes 必须位于与公共 IP 地址相同的区域,你将从该范围分配地址。Must exist in the same regionas the public IP addresses you'll assign addresses from the range.
    前缀大小Prefix size Yes 所需的前缀大小。The size of the prefix you need. /28 或 16 个 IP 地址为默认值。A /28 or 16 IP addresses is the default.

**** 命令Commands

工具Tool 命令Command
CLICLI az network public-ip prefix createaz network public-ip prefix create
PowerShellPowerShell New-AzPublicIpPrefixNew-AzPublicIpPrefix

从前缀创建静态公共 IP 地址Create a static public IP address from a prefix

在创建前缀后,必须从前缀创建静态 IP 地址。Once you create a prefix, you must create static IP addresses from the prefix. 为此,请执行以下步骤。In order to do this, follow steps below.

  1. 在 Azure 门户顶部包含“搜索资源”文本的框中,键入“公共 IP 前缀”** **。In the box that contains the text Search resources at the top of the Azure portal, type Public IP Prefix. 当“公共 IP 前缀”**** 出现在搜索结果中时,请选择它。When Public IP Prefixes appear in the search results, select it.

  2. 选择想要通过其创建公共 IP 的前缀。Select the prefix you want to create public IPs from.

  3. 当出现在搜索结果中,选择它,然后单击“概述”部分中的“+添加 IP 地址”****。When it appears in the search results, select it and click on +Add IP address in the Overview section.

  4. 在“创建公共 IP 地址”**** 下为以下设置输入或选择值。Enter or select values for the following settings under Create public IP address. 由于前缀适用于标准 SKU、IPv4 和静态,因此只需提供以下信息:Since a prefix is for Standard SKU, IPv4, and static, you only need to provide the following information:

    设置Setting 必需?Required? 详细信息Details
    名称Name Yes 公共 IP 地址的名称在所选的资源组中必须唯一。The name of the public IP address must be unique within the resource group you select.
    空闲超时(分钟)Idle timeout (minutes) No 在不依赖客户端发送保持连接消息的情况下,TCP 或 HTTP 连接持续打开的分钟数。How many minutes to keep a TCP or HTTP connection open without relying on clients to send keep-alive messages.
    DNS 名称标签DNS name label No 必须在创建该名称的 Azure 区域(跨所有订阅和所有客户)中保持唯一。Must be unique within the Azure region you create the name in (across all subscriptions and all customers). Azure 会在其 DNS 中自动注册该名称和 IP 地址,使你能够连接到使用该名称的资源。Azure automatically registers the name and IP address in its DNS so you can connect to a resource with the name. Azure 会将 location.cloudapp.chinacloudapi.cn(其中 location 是所选的位置)之类的默认子网追加到提供的名称后面,以创建完全限定的 DNS 名称。有关详细信息,请参阅将 Azure DNS 与 Azure 公共 IP 地址配合使用Azure appends a default subnet such as location.cloudapp.chinacloudapi.cn (where location is the location you select) to the name you provide, to create the fully qualified DNS name.For more information, see Use Azure DNS with an Azure public IP address.

或者,可以使用下面的 CLI 和 PS 命令以及 -public-ip-prefix (CLI)和 -PublicIpPrefix (PS) 参数来创建公共 IP 地址资源。Alternatively you may use the CLI and PS commands below with the --public-ip-prefix (CLI) and -PublicIpPrefix (PS) parameters, to create a Public IP address resource.

工具Tool 命令Command
CLICLI az network public-ip createaz network public-ip create
PowerShellPowerShell New-AzPublicIpAddressNew-AzPublicIpAddress

查看或删除前缀View or delete a prefix

  1. 在 Azure 门户顶部包含“搜索资源”文本的框中,键入“公共 IP 前缀”** **。In the box that contains the text Search resources at the top of the Azure portal, type Public IP Prefix. 当“公共 IP 前缀”**** 出现在搜索结果中时,请选择它。When Public IP prefixes appear in the search results, select it.
  2. 选择要查看、更改其设置或从列表中删除的公共 IP 前缀的名称。Select the name of the public IP prefix that you want to view, change settings for, or delete from the list.
  3. 根据是要查看、删除还是更改公共 IP 前缀,完成以下选项之一。Complete one of the following options, depending on whether you want to view, delete, or change the public IP prefix.
    • 视图:“概述”**** 部分显示公共 IP 前缀的关键设置,如前缀。View: The Overview section shows key settings for the public IP prefix, such as prefix.
    • 删除:若要删除公共 IP 前缀,请在“概述”**** 部分中选择“删除”****。Delete: To delete the public IP prefix, select Delete in the Overview section. 如果前缀中的地址关联到公共 IP 地址资源,必须先删除公共 IP 地址资源。If addresses within the prefix are associated to public IP address resources, you must first delete the public IP address resources. 请参阅删除公共 IP 地址See delete a public IP address.

**** 命令Commands

工具Tool 命令Command
CLICLI az network public-ip prefix list 用于列出公共 IP 地址;az network public-ip prefix show 用于显示设置;az network public-ip prefix update 用于更新;az network public-ip prefix delete 用于删除az network public-ip prefix list to list public IP addresses, az network public-ip prefix show to show settings; az network public-ip prefix update to update; az network public-ip prefix delete to delete
PowerShellPowerShell Get-AzPublicIpPrefix 用于检索公共 IP 地址对象并查看其设置;Set-AzPublicIpPrefix 用于更新设置;Remove-AzPublicIpPrefix 用于删除Get-AzPublicIpPrefix to retrieve a public IP address object and view its settings, Set-AzPublicIpPrefix to update settings; Remove-AzPublicIpPrefix to delete

权限Permissions

若要对公共 IP 前缀执行任务,必须将你的帐户分配给网络参与者角色或分配有下表中所列相应操作的自定义角色:To perform tasks on public IP prefixes, your account must be assigned to the network contributor role or to a custom role that is assigned the appropriate actions listed in the following table:

操作Action 名称Name
Microsoft.Network/publicIPPrefixes/readMicrosoft.Network/publicIPPrefixes/read 读取公共 IP 前缀Read a public IP prefix
Microsoft.Network/publicIPPrefixes/writeMicrosoft.Network/publicIPPrefixes/write 创建或更新公共 IP 前缀Create or update a public IP prefix
Microsoft.Network/publicIPPrefixes/deleteMicrosoft.Network/publicIPPrefixes/delete 删除公共 IP 前缀Delete a public IP prefix
Microsoft.Network/publicIPPrefixes/join/actionMicrosoft.Network/publicIPPrefixes/join/action 从前缀创建公共 IP 地址Create a public IP address from a prefix

后续步骤Next steps