Use Reserved IP Address for Cloud Service and VM in Virtual Network

Learn how a cloud service can have a reserved IP address and the virtual machine inside can still be attached to a virtual network.

John Savill

November 18, 2014

1 Min Read
virtual IP address

Q: Can I configure a reserved IP address for a cloud service hosting IaaS virtual machines and set the virtual machine to be part of a virtual network?

A: It's possible to reserve IP addresses for the lifetime of an Azure subscription, which ensures that the cloud service maintains the same public IP address even if the service is deprovisioned at some point. (See "Reserved IP addresses for Cloud Services & Virtual Machines" for more information.) The reserved IP address isn't assigned to the virtual machine but instead to the cloud service the virtual machine is created in. The reserved IP address is used for the cloud service virtual IP address. This reserved IP address for the cloud service virtual IP address is completely separate from the dynamic IP address the virtual machine has, which can be part of a virtual network and virtual subnet. The following code shows an example of reserving a new IP address, then using it in a new virtual machine creation that also creates a new cloud service.

#This code just finds the latest Windows Server 2012 R2 Datacenter image$images = Get-AzureVMImage$2012R2imgs = @() #Create array of objectsforeach ($image in $images){    if ($image.Label.Contains("Windows Server 2012 R2 Datacenter"))    {        $2012R2imgs += $image    }}$2012R2imgs = $2012R2imgs | Sort-Object PublishedDate -Descending #put the newest first which is the highest patched version#Create a new Reserved IP address$ReservedIP = New-AzureReservedIP –ReservedIPName "TestReserve1" –Label "TestReserve1" –Location "East US"#Use the new Reserved IP address also note a Virtual Subnet and Virtual Network are specified, App-Net and VirtNet115 respectivelyNew-AzureVMConfig -Name "TestVM55" -InstanceSize 'Basic_A2' -ImageName $2012R2imgs[0].ImageName |     Add-AzureProvisioningConfig -Windows -AdminUsername cloudguy -Password Pa55word!123 |     Set-AzureSubnet 'App-Net' |    New-AzureVM -ServiceName "SavillTech103" –ReservedIPName 'TestReserve1' -Location 'East US' -VNetName 'VirtNet115'

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like