Quick blog post on a simple and logic error that you might get when you´re trying to set a static IP on your Microsoft Azure VM.
So as you can see above, when you try and run:
Get-AzureVM -ServiceName MYMSEXCHANGE -Name TestVNetVM |Set-AzureStaticVNetIP -IPAddress 192.168.0.150 |Update-AzureVM
You get the error:
“Update-AzureVM : BadRequest : The static address 192.168.0.150 doesn’t belong to the address space defined by the role’s subnets.”
The reason behind this error is simple: You are trying to set a static IP for your VM that does not belong to the subnet where the VM is. So let’s have a quick look on how to see which subnet does your VM belongs to. From the azure PowerShell run:
$MyVM = Get-AzureVM -ServiceName MYMSEXCHANGE -Name TestVNetVM
Get-AzureSubnet -VM $MyVM
The output will show you the Subnet of your VM.
You can also see the network where your VM is on by running:
Get-AzureVM |fl Name, VirtualNetworkName
Now that you know what network and subnet your VM is on, you can go to the Azure Portal > Networks, and on the Configure tab of the network you can see the range of IP addresses from the subnet of your VM:
In my case the VM is on the subnet-2, with a range of Ip’s of 192.168.1.0/24 and i was trying to set up an IP address on the 192.168.0.0/24 range.
Let’s try with a valid IP now on the 192.168.1.0/24 network:
No error, job done, and as simple as it gets! 🙂