使用 Azure 经典管理门户中创建的虚拟机,无法使用静态IP 地址,在管理界面没有该设置。
在新的管理门户中虽然有使用静态IP的设置,但是选项是灰色,无法修改,提示错误:This virtual machine can't be configured with a static private IP address because it's not deployed in a virtual network.
默认情况下,Azure中的虚拟机关机后重启,会重新分配IP地址。生产环境中,为了和其它的系统集成或者方便管理,需要使用静态IP地址。
故障原因:
经典门户采用的是ASM部署模型,默认虚拟机不属于某个虚拟网络,所以无法通过新管理门户中虚拟网络的设置来更改成静态IP。
解决方法:
一、将虚拟机从经典门户中删除,但保留VHD文件,再复制该文件到新门户的存储中,然后通过新门户重新创建虚拟机并设置使用静态IP地址。
优点:可以图形化操作;并且采用新的ARM部署模型,方便以后管理,一劳永逸。
缺点:操作复杂,费时
二、通过Powershell命令来设置静态IP地址,命令如下:
PS C:\WINDOWS\system32> New-AzureReservedIP -ReservedIPName zxreservedipasm -location "China East" -ServiceName chengyuanapp
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
New-AzureReservedIP 49fcc950-ca01-4d9c-90cc-f82d20df086b Succeeded
更改完成后,显示该IP地址为Reserved:
另,如果要删除保留IP时,要先删除关联(Remove-AzureReservedIPAssociation),再删除保留IP(Remove-AzureReservedIP),命令如下:
PS C:\WINDOWS\system32> Remove-AzureReservedIPAssociation -ReservedIPName zxreservedipasm -ServiceName chengyuanapp
Remove Reserved IP Association
This cmdlet will remove the reserved ip association from the specified service. Do you want to continue?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
Remove-AzureReservedIPAssociation 518e6c5d-c91e-4ba1-a33d-720b6ee8f999 Succeeded
PS C:\WINDOWS\system32> Remove-AzureReservedIP -ReservedIPName "zxreservedipasm"
Confirm
Are you sure you want to remove the Reserved IP from your subscription?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
Remove-AzureReservedIP bdac1206-8360-4861-8f13-703e92d8dc66 Succeeded
参考文档:
https://www.azure.cn/documentation/articles/virtual-networks-reserved-public-ip/