Static Internal IP Address for Windows Azure VMs

WinAzureOn the same day I published my Azure Newbie Notes post, which mentioned, among other things, the inability to set static IP address for VMs, things changed a bit. Then-new v0.7.3 of Windows Azure PowerShell added several cmdlets that allow handling of static internal IP addresses. This came without any official announcements, but was covered in several blog posts on TechNet. No doubt this is a must-have feature – many services just won’t operate correctly without constant IP address, with DNS server is probably the most notable among them. Unfortunately, configuring static IP address via web-based Azure Management Console is not available yet.

[ Here you can find brief explanation on how to install and configure Azure PowerShell, along with the some related links. ]

Several posts and articles with useful samples related to static IP addresses:

Here and in the samples below “MyVM” is the name of the virtual machine we want to update and “MyCloudService” is the name of the cloud service this VM belongs to.

Probably the most useful sample nowadays is one that shows how to take existing VM and set it to have a static IP address. Although most of the articles say you have to use an available (that is, free) IP address, you can use the same IP address that is already assigned to the specific VM. Also, pay attention that Update-AzureVM cmdlet reboots the VM. Note that in the sample run below I’m configuring MyVM to the same IP address it already has. Of course, it makes sense to run the first part of the command alone first to make sure you are going to update the right VM.

Get-AzureVM -ServiceName MyCloudService -Name MyVM | Set-AzureStaticVNetIP -IPAddress 10.0.0.100 | Update-AzureVM

Another useful command is to check whether a VM already has a static IP address configured or not. For VMs with static IP address configured, this IP will be displayed, otherwise only the diagnostic output of the first part will be shown.

Get-AzureVM -ServiceName MyCloudService -Name MyVM | Get-AzureStaticVNetIP


Finally, the ultimate sample:

PS C:\> Get-AzureVM -ServiceName MyCloudService -Name MyVM
VERBOSE: 8:26:04 AM - Completed Operation: Get Deployment


DeploymentName              : MyVM
Name                        : MyVM
Label                       :
VM                          : Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM
InstanceStatus              : ReadyRole
IpAddress                   : 10.4.4.4
InstanceStateDetails        :
PowerState                  : Started
InstanceErrorCode           :
InstanceFaultDomain         : 0
InstanceName                : MyVM
InstanceUpgradeDomain       : 0
InstanceSize                : Medium
AvailabilitySetName         :
DNSName                     : http://MyCloudService.cloudapp.net/
Status                      : ReadyRole
GuestAgentStatus            : Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.GuestAgentStatus
ResourceExtensionStatusList : {Microsoft.Compute.BGInfo}
ServiceName                 : MyCloudService
OperationDescription        : Get-AzureVM
OperationId                 : 8f5e3d5dfbcd9c37b85b34866da969ab
OperationStatus             : OK


PS C:\> Get-AzureVM -ServiceName MyCloudService -Name MyVM | Get-AzureStaticVNetIP
VERBOSE: 10:01:12 AM - Completed Operation: Get Deployment

PS C:\> Get-AzureVM -ServiceName MyCloudService -Name MyVM | Set-AzureStaticVNetIP -IPAddress  10.4.4.4 | Update-AzureVM
VERBOSE: 8:26:55 AM - Completed Operation: Get Deployment
VERBOSE: 8:26:56 AM - Completed Operation: Get Deployment
VERBOSE: 8:26:56 AM - Begin Operation: Update-AzureVM
VERBOSE: 8:27:28 AM - Completed Operation: Update-AzureVM

OperationDescription                    OperationId                             OperationStatus
--------------------                    -----------                             ---------------
Update-AzureVM                          ee32f2d6-0f3b-93c9-ba48-86ed38135c03    Succeeded

PS C:\> Get-AzureVM -ServiceName MyCloudService -Name MyVM | Get-AzureStaticVNetIP
VERBOSE: 10:01:12 AM - Completed Operation: Get Deployment

IPAddress
---------
10.4.4.4

PS C:>

Enjoy!

One thought on “Static Internal IP Address for Windows Azure VMs

Leave a Reply