As a static internal IP address (DIP) stays with the VM even though the VM is in a stopped (deallocated) status, in some cases, a static DIP is necessary for your Azure Virtual machine (VM).
Now you can assign a static DIP to an existing Azure VM or at the time you create the VM via Azure PowerShell. To specify a static DIP to an existing VM, you can use the Azure PowerShell commands below:
Get-AzureVM –ServiceName “xxx” –Name “xxx” | Set-AzureStaticVnetIP –IPAddress “xxx” | Update-AzureVM
(Note: –ServiceName is the DNS name of the cloud service that VM belongs to, –Name is the host name of the VM, –IPAddress is the static DIP you want to assign to the VM in the virtual network that VM belongs to)
In this article, we introduce the troubleshooting steps for common issues when specifying a static DIP to an existing VM.
Error message 1:
Update-AzureVM : Networking.DeploymentVNetAddressAllocationFailure : Unable to allocate the required address spaces for the deployment in a new or predefined subnet that is contained within the specified virtual network.
Reason:
It is due to the static DIP you assign to the VM is not available.
Solution:
Ensure the static DIP that you want to assign is available in the virtual network by using the Azure PowerShell command below:
Test-AzureStaticVNetIP –VNetName “xxx” –IPAddress “xxx”
If the DIP is unavailable, you can see theFalse in the returned results. (Figure 1)
Figure 1.
Since that IP address is assigned to another VM, you have two options:
1. Assign another available address in that subnet to the VM instead. (Recommend)
2. Remove this DIP from the other VM and then assign this IP address to the VM.
If the DIP is not assigned as a static DIP to the other VM, you can shut down the other VM to the stopped (deallocated) status then the internal IP address would be released. Otherwise, you can run the commands below to remove the static DIP from the other VM firstly:
Get-AzureVM -ServiceName “xxx” -Name “xxx” | Remove-AzureStaticVNetIP | Update-AzureVM
Error message 2:
Update-AzureVM: BadRequest : The static address xxx doesn’t belong to the address space defined by the roles’s subnets.
Figure 2.
Reason:
This error is due to the static DIP is not in the subnet which the VM belongs to.
Solution:
Check the existing internal IP address for the VM in the virtual network Dashboard and the address spaces in the virtual network configure page to make sure the subnet the VM belongs to. (Figure 3 and Figure 4) After that, specify a static DIP in the correct subnet to the VM.
Figure 3.
Figure 4.
From Figure 3 & Figure 4, we can see that test02 belongs to DIP1 instead of DIP2, while the IP address 10.0.0.21 belongs to DIP2, that’s the reason why we got the error in Figure 2.
After we changed the IP address to an IP address in DIP1, it worked. (Figure 5)
Figure 5.
Error 3:
Update-AzureVM: BadRequest : The value for parameter “Subnetnames” is null or empty.
Figure 6.
Reason:
It is due to the VM isn’t in the virtual network that the static DIP belongs to.
Solution:
Scenario 1:
If the locations of the VM and the virtual network are the same, you can delete the VM and keep the attached disks, then use the disk to recreate a new VM to that Virtual network. You can also do those by Azure PowerShell or in Azure management portal:
1. Using Azure PowerShell
(1) Remove the VM and keep the disks (.vhd)
Remove-AzureVM -ServiceName “xxx” –Name ”xxx”
Figure 7.
(2) Obtain the disk name
You can run the command below to get data for all of the disks in the disk repository that are not currently attached to a virtual machine:
Get-AzureDisk | Where-Object {$_.AttachedTo –eq $null }
Figure 8.
Then Cope the DISK Name.
(3) Create a new VM using that disk to the virtual network and assign the static DIP to the VM:
New-AzureVMConfig -Name “xxx” -DiskName “xx” –InstanceSize Small | Set-AzureSubnet –SubnetNames “xxx” | Set-AzureStaticVNetIP -IPAddress “xxx” | New-AzureVM –ServiceName ”xxx”–VNetName “xxx”
Figure 9.
(Note: The command above can only be used if you have an existing cloud service in that virtual network. If not, you cannot create a cloud service to a virtual network when creating a VM in Azure PowerShell. Or you will receive the error message “The hosted service does not exist.)
After that, you can see the VM is created and assigned with the static DIP.
Figure 10.
2. Using Azure management portal
(1) Delete the VM and choose theKeep the attached disks option. (Figure)
Figure 11.
(2) After a few minutes, make sure the disk is not attached to a VM in the DISKS page of the Virtual Machines.
Figure 12.
(3) Create a new VM using and choose that disk as an image.
Figure 13.
(4) Select the virtual network/subnet which the DIP belongs to.
You can create a new cloud service, or you can also add it into an existing cloud service if this cloud service is also associated with that virtual network.
Figure 14.
(5) After the VM is created and running, you can use the commands below to assign a static DIP to the VM.Get-AzureVM –ServiceName “xxx” –Name “xxx” | Set-AzureStaticVnetIP –IPAddress “xxx” | Update-AzureVM
Scenario 2:
If the locations of the VM and the virtual network are different, you can create a new virtual network in the location of the VM (recommend) or a new VM in the location of the virtual network (if there is no important data /configurations on the existing VM) and then follow the steps in scenario 1 to achieve that.
More information:
Configure a Static Internal IP Address for a VM
http://msdn.microsoft.com/en-us/library/azure/dn630228.aspx
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.