Sometimes it can be necessary to change the network structure of the virtual machines in Azure, e.g. to move VMs into a virtual network for the setting up of VPNs.
To do so, the internal, static IP of the respective VMs needs to be changed.
Index
Possible Scenarios
Let’s take a look at two different scenarios:
- The VM is not located in any virtual net/ subnet or is located in another virtual net/ subnet.
- The VM is already located in the target-network and only the static IP has to be changed.
If you are only interested in the second scenario, please feel free to skip the first part of this article and head straight on to the section “Change the Static IP-Address of a VM“.
In case the virtual machine is located in another virtual network/ subnet, the process proves to be a little more complex. Before being able to change the static IP-address, the VM has to move to the new subnet.
Include VM into Another Subnet
The problem is that you cannot simply move a machine within Azure. The solution is to delete the VM and to create a new one at the other subnet by using a virtual hard drive.
In a first step, you should save your current VM, e.g. by creating an image of the hard drive with Azure (left in the menu: Virtual Computer > Images).
Next, select the respective VM and click “Delete” in the bottom page margin menu. Select “Keep attached drive” from the menu to preserve the virtual hard drive and not delete it along with the machine. Confirm your entry and wait until Azure finishes the process.
By clicking “New” (bottom left), you can then create a new VM. It is important not to select the quick version but the option “From Catalogue” to be able to make an additional configuration for the to-be-created machine.
In the next dialogue, you can select the image from which the VM is to be created. Click “Own drive” on the left side navigation and search for the virtual hard drive of the previously deleted machine.
Go on and choose a name for the machine and select the desired hardware configuration. Afterwards, assign a cloud service to the VM on the third configuration page. Go to “Region/ Affinity-Groups / Virtual Network” and “Virtual Network – Subnetworks” to select which virtual network and subnet the new machine should belong to.
On the last page of the configuration, specify which add-ons should be installed and confirm your entries. Azure then creates a VM with the selected settings in the chosen virtual network/ subnet. As the static IP will be assigned automatically, it has to be changed later on to the desired one.
Change the Static IP Address of a VM
To change the static IP address, you need the Microsoft Azure Powershell for the administration of your cloud. The article Manage Azure Virtual Machines with PowerShell explains how to install and configure it.
After your PowerShell is ready to communicate with your Azure environment, you can start the process of changing the static IP address. But first, ensure the desired IP to be existent in your virtual network. If you have a manageable number of VMs, do that via the Azure dashboard. Alternatively, use the Azure PowerShell and the following command:
Test-AzureStaticVNetIP -VNetName test-fa -IPAddress 10.20.0.11
Enter the name of the virtual network to be checked in the parameter “VNetName” and the IP address in “IPAddress”. Make sure that the IP you selected lies within the specified address range of the subnet you want to use for the machine in the future. Is the address still available, PowerShell will output “True” for IsAvailable. Is it not, you either have to choose another or clear the desired IP.
Now it is about assigning the new static IP of the VM. For this, a PowerShell command is used as well:
Get-AzureVM -ServiceName fa-test -Name test-win2012r2 | Set-AzureStaticVNetIP -IPAddress 10.20.0.11 | Update-AzureVM
The following parameters are to be entered:
- ServiceName: Name of the cloud service under which the VM is reachable.
- Name: Name of the virtual machine.
- IPAddress: Desired IP-address
Confirm your entry with Enter and wait until the PowerShell has successfully completed all actions.
Now, you should see the new static IP of the VM.
Please contact us if you would like to know more
Leave a Reply
<p>Your email is safe with us.<br/>Information about our <a href="https://activedirectoryfaq.com/contact-us/">data protection policies</a></p>