快速入门:使用 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 的 IPv6。For this example, we will focus on IPv4 addresses only; for more information on IPv6 addresses, see IPv6 for Azure VNet.
先决条件Prerequisites
- 本地安装的 Azure PowerShell 或 Azure 本地 ShellAzure PowerShell installed locally or Azure local Shell
备注
本文进行了更新,以便使用新的 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 PowerShell。For Az module installation instructions, see Install Azure PowerShell.
如果选择在本地安装并使用 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
基本 SKUBasic SKU
使用 New-AzPublicIpAddress 在 myResourceGroup 中创建名为“myBasicPublicIP”的基本静态公共 IP 地址 。Use New-AzPublicIpAddress to create a basic static public IP address named myBasicPublicIP in myResourceGroup.
## Variables for the command ##
$rg = 'myResourceGroup'
$loc = 'chinaeast2'
$pubIP = 'myBasicPublicIP'
$sku = 'Basic'
$alloc = 'Static'
New-AzPublicIpAddress -ResourceGroupName $rg -Name $pubIP -Location $loc -AllocationMethod $alloc -SKU $sku
如果可以接受 IP 地址随时间而变这种情况,可通过将 AllocationMethod 更改为“Dynamic”来选择动态 IP 分配。If it is acceptable for the IP address to change over time, Dynamic IP assignment can be selected by changing the AllocationMethod to 'Dynamic'.
其他信息Additional information
若要更详细地了解以上所列各个变量,请参阅管理公共 IP 地址。For more details on the individual variables listed above, please see Manage public IP addresses.
后续步骤Next steps
- 将公共 IP 地址关联到虚拟机Associate a public IP address to a Virtual Machine
- 详细了解 Azure 中的公共 IP 地址。Learn more about public IP addresses in Azure.
- 详细了解所有公共 IP 地址设置。Learn more about all public IP address settings.