Home » Posts tagged 'New-AzureVMConfig'
Tag Archives: New-AzureVMConfig
By default every VM will automatically receive an internal IP address from a range that you specify
But in some case you need to specify a static IP for your VM like (DNS , Domain controller , …….)
To assign a static IP to the VM , you have first to Install Azure Powershell
Before you specify a static IP address from your address pool, you may want to verify that the IP address has not been already assigned. In the example below, we’re checking to see whether the IP address 192.168.4.7 is available in the TestVNet virtual network.
Test-AzureStaticVNetIP –VNetName TestVNet –IPAddress 192.168.4.7
If you have already created the VM and just want to assign the the static IP
If you already set an IP address for the VM and you want to change it to a different IP address, you’ll need to remove the existing static IP address before running these cmdlets. See the instructions below to remove a static IP.
Get-AzureVM -ServiceName StaticDemo -Name VM2 | Set-AzureStaticVNetIP -IPAddress 192.168.4.7 | Update-AzureVM
If the VM is not yet created and you need to created with the static IP
New-AzureVMConfig -Name $vmname -ImageName $img –InstanceSize Small | Set-AzureSubnet –SubnetNames $sub | Set-AzureStaticVNetIP -IPAddress 192.168.4.7 | New-AzureVM –ServiceName $vmsvc1 –VNetName TestVNet
No how can your remove a static IP from a VM
When you remove a static IP address from a VM, the VM will automatically receive a new DIP after the VM restarts as part of the update process. In the example below, we remove the static IP from VM2, which is located in cloud service StaticDemo.
Get-AzureVM -ServiceName StaticDemo -Name VM2 | Remove-AzureStaticVNetIP | Update-AzureVM
Source: Azure MSDN