Azure经典门户创建VM,怎么设置使用静态IP地址

Azure经典门户创建VM,如何设置使用静态IP地址?

使用 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经典门户创建VM,怎么设置使用静态IP地址
默认情况下,Azure中的虚拟机关机后重启,会重新分配IP地址。生产环境中,为了和其它的系统集成或者方便管理,需要使用静态IP地址。

 

故障原因:
经典门户采用的是ASM部署模型,默认虚拟机不属于某个虚拟网络,所以无法通过新管理门户中虚拟网络的设置来更改成静态IP。


解决方法:
一、将虚拟机从经典门户中删除,但保留VHD文件,再复制该文件到新门户的存储中,然后通过新门户重新创建虚拟机并设置使用静态IP地址。
优点:可以图形化操作;并且采用新的ARM部署模型,方便以后管理,一劳永逸。
缺点:操作复杂,费时


二、通过Powershell命令来设置静态IP地址,命令如下:

Azure经典门户创建VM,怎么设置使用静态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:

Azure经典门户创建VM,怎么设置使用静态IP地址


另,如果要删除保留IP时,要先删除关联(Remove-AzureReservedIPAssociation),再删除保留IP(Remove-AzureReservedIP),命令如下:

Azure经典门户创建VM,怎么设置使用静态IP地址
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/

 

1楼PowerShell免费软件
实际上,外网动态ip地址更好。能解决博客园被ddos问题。无需担心解析问题。,1可以认为你的ip是秒变的,而dns解析,也是秒跟随的。,2这时攻击你的外网ip已经无用,无意义。只能攻击你的dns。,3你的思路很对,powershell脚本可以解决快速解决一切,运维问题。