快速入门:使用 Azure PowerShell 创建公共 IP 地址Quickstart: Create a public IP address using Azure PowerShell

本文介绍如何使用 Azure PowerShell 来创建公共 IP 地址资源。This article shows you how to create a public IP address resource using Azure PowerShell. 若要详细了解此操作可以关联到的具体资源、基本 SKU 和标准 SKU 之间的差异,以及其他相关信息,请参阅公共 IP 地址For more information on which resources this can be associated to, the difference between Basic and Standard SKU, and other related information, please see Public IP addresses. 对于此示例,我们只重点介绍 IPv4 地址;有关 IPv6 地址的详细信息,请参阅适用于 Azure VNet 的 IPv6For this example, we will focus on IPv4 addresses only; for more information on IPv6 addresses, see IPv6 for Azure VNet.

先决条件Prerequisites

  • 在本地安装了 Azure PowerShellAzure PowerShell installed locally

备注

本文已经过更新,以便使用 Azure Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShellTo get started with the Az PowerShell module, see Install Azure PowerShell. 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 AzTo learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

如果选择在本地安装并使用 PowerShell,则本文需要 Azure PowerShell 模块 5.4.1 或更高版本。If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. 运行 Get-Module -ListAvailable Az 查找已安装的版本。Run Get-Module -ListAvailable Az to find the installed version. 如果需要升级,请参阅安装 Azure PowerShell 模块If you need to upgrade, see Install Azure PowerShell module. 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount -Environment AzureChinaCloud 以创建与 Azure 的连接。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

Azure 资源组是在其中部署和管理 Azure 资源的逻辑容器。An Azure resource group is a logical container into which Azure resources are deployed and managed.

使用 New-AzResourceGroup 在 chinaeast2 位置创建名为“myResourceGroup”的资源组 。Create a resource group with New-AzResourceGroup named myResourceGroup in the chinaeast2 location.

## Variables for the command ##
$rg = 'myResourceGroup'
$loc = 'chinaeast2'

New-AzResourceGroup -Name $rg -Location $loc

创建公共 IPCreate public IP


备注

以下命令适用于 Az.Network 模块版本 4.5.0 或更高版本。The following command works for Az.Network module version 4.5.0 or later. 有关当前正在使用的 Powershell 模块的详细信息,请参阅 PowerShellGet 文档For more information about the Powershell modules currently being used, please refer to the PowerShellGet documentation.

使用 New-AzPublicIpAddress 在 myResourceGroup 中创建一个标准公共 IP 地址作为名为 myStandardPublicIP 的非区域性资源 。Use New-AzPublicIpAddress to create a standard public IP address as a non-zonal resource named myStandardPublicIP in myResourceGroup.

## Variables for the command ##
$rg = 'myResourceGroup'
$loc = 'chinaeast2'
$pubIP = 'myStandardPublicIP'
$sku = 'Standard'
$alloc = 'Static'

New-AzPublicIpAddress -ResourceGroupName $rg -Name $pubIP -Location $loc -AllocationMethod $alloc -SKU $sku

此选择在所有区域均有效,并且目前在 Azure 中国世纪互联中,这是标准公共 IP 地址区域的默认选择。This selection is valid in all regions and is the default selection for Standard Public IP addresses regions in Azure China 21Vianet currently.

其他信息Additional information

若要更详细地了解以上所列各个变量,请参阅管理公共 IP 地址For more details on the individual variables listed above, please see Manage public IP addresses.

后续步骤Next steps