5

Can't we Move a Microsoft Azure VM to a Different Subnet Within a vNet using the azure new portal or the azure classic portal ? if not possible through portal then how to do so ?then how to edit the properties of a VM after creation, like moving to a different subnet,, etc.,?

Mohamed Uvais M
  • 185
  • 1
  • 2
  • 14
  • This question has already been answered here - http://stackoverflow.com/questions/35349166/azure-power-shell-how-to-change-network-subnet – Aatif Akhter Sep 09 '16 at 09:56

3 Answers3

11

It is possible through the new portal. First I want to ask you if you're using a Classic VM or a Resource manager VM. If you're using the last one you can easily switch between subnets by changing the configuration settings. go to your network interface > Ip configurations and click on the Nic name (see picture below)

View nic Azure

A new tab will open and you can change the Subnet of the nic.

Change Subnet

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Ivo Haagen
  • 111
  • 5
2

If your vm is a classic one, moving it to different vNet is very easy using azure powershell cmdlets. Here is the code-

$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
Aatif Akhter
  • 2,126
  • 1
  • 25
  • 46
  • This question has already been answered for ARM vm - http://stackoverflow.com/questions/35349166/azure-power-shell-how-to-change-network-subnet I am adding my answer here as this deals with classic vm – Aatif Akhter Sep 09 '16 at 20:39
0

if not possible through portal then how to do so ?then how to edit the properties of a VM after creation, like moving to a different subnet,, etc.,?

It could be done with Powershell. In brief, it contains 3 steps:

  1. Get the VM (NIC) configuration
  2. Edit the VM (NIC) configuration
  3. Update the edited configuration

Note: Moving VMs between different VNET is not supported. To move the VM to another VNET, the only solution for now is re-create the VM with the same vhd file.

Here is a good step-by-step guide:

How to change Subnet and Virtual Network for Azure Virtual Machines (ASM & ARM)