How to change an Azure VM Subnet

December 2, 2015 at 8:22 am in Azure, Microsoft by Florent

microsoft-azure-logo

Yestarday I created a SQL VM on Azure. I completed the installation and so on, but after, I saw that the VM was not in the good subnet in my network.

I searched on Internet how to change the subnet and I found this documentation.

So, I will explain to you how to do this with PowerShell (this is the only possibility to do this). As you can see, I have the IP address 10.0.0.4:

SNAGHTML21dc9f7b

My two subnet in my network are the following:

SNAGHTML21d5b844

As you can see, the VM is actually in the FrontEnd subnet and I would like to move it in the BackEnd subnet. To do this, execute the following PowerShell command:

Get-AzureVM -Name sql-001 -ServiceName Demo | Set-AzureSubnet -SubnetNames BackEnd | Update-AzureVM

SNAGHTML21db5a77

The VM will restart after the execution of the Update-AzureVM cmdlet. When it’s done, go back to your Azure VM interface. You can see that the new IP is in my BackEnd range:

SNAGHTML21df4df1

Don’t forget to change the IP in your DNS too if you don’t allow DNS Dynamic Updates. In my VM, I have the following IP:

SNAGHTML220bb08d