【问题标题】:Move a Microsoft Azure VM to a Different Subnet Within a vNet将 Microsoft Azure VM 移动到 vNet 中的不同子网
【发布时间】:2017-01-16 06:20:50
【问题描述】:
我们不能使用 azure new 门户或 azure classic 门户将 Microsoft Azure VM 移动到 vNet 中的不同子网吗?如果无法通过门户网站,那么该怎么做?那么如何在创建后编辑 VM 的属性,例如移动到不同的子网等?
【问题讨论】:
标签:
azure
azure-virtual-machine
azure-cloud-services
azure-virtual-network
azureportal
【解决方案1】:
可以通过新门户。首先,我想问您使用的是经典 VM 还是资源管理器 VM。如果您使用最后一个,您可以通过更改配置设置轻松地在子网之间切换。
转到您的网络接口 > Ip 配置,然后单击 Nic 名称(见下图)
将打开一个新选项卡,您可以更改 nic 的子网。
【解决方案2】:
如果您的虚拟机是经典虚拟机,则使用 azure powershell cmdlet 将其移动到不同的 vNet 非常容易。这是代码-
$vmName = "xxxxx"
$srcServiceName = "xxxxx"
$newVNet = "xxxxx"
# export vm config file
$workingDir = (Get-Location).Path
$sourceVm = Get-AzureVM –ServiceName $srcServiceName –Name $vmName
$global:vmConfigurationPath = $workingDir + "\exportedVM.xml"
$sourceVm | Export-AzureVM -Path $vmConfigurationPath
# remove vm keeping the vhds and spin new vm using old configuration file but in a new vNet
Remove-azurevm –ServiceName $srcServiceName –Name $vmName
$vmConfig = Import-AzureVM -Path $vmConfigurationPath
New-AzureVM -ServiceName $srcServiceName -VMs $vmConfig -VNetName $newVNet -WaitForBoot