Configuring static IP addresses on Azure VM’s

I’ve been doing a lot of Azure IaaS lately and got some things to share. This is the first of multiple posts about Azure VM’s and such.

Microsoft has recently added the ability to set static IP addresses on VM’s created in Azure. Some things you should be aware of:

  • You can only set a static IP address using PowerShell, not the Azure portal (for now at least..)
  • The IP address is set when you create the VM – you cannot change it afterwards or on an existing VM
  • You need at least version of the Azure command-line tools, you can get the newest version here:

So, how is this done?

Simple: Use Set-AzureStaticVNetIP when creating your VM. Example:

[powershell]$vmName = "TESTVM1"
$vmSize = "Small" #ExtraSmall, Small, Medium, Large, ExtraLarge, A6, A7
$imageName = "" #Use Get-AzureVMImage to list the available images
$domainAdmin = "jj-admin"
$domainAdminPw = Read-Host "Enter domain admin password:"
$domain = "domain"
$domainFqdn = ""
$localAdmin = "jj"
$localAdminPw = Read-Host "Enter local admin password:"
$subnet = "BackEndSubnet"
$ipAddress = ""
$serviceName = "jjlab"

$vm = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -ImageName $imageName
$vm | Add-AzureProvisioningConfig -WindowsDomain `
-AdminUsername $localAdmin `
-Password $localAdminPw `
-DomainUserName $domainAdmin `
-DomainPassword $domainAdminPw `
-JoinDomain $domainFqdn `
-Domain $domain
$vm | Set-AzureSubnet -SubnetNames $subnet
$vm | Set-AzureStaticVNetIP -IPAddress $ipAddress
New-AzureVM -VMs $vm -ServiceName $serviceName[/powershell]

Currently there is no way to avoid passwords in plain text. Hopefully this will be added soon.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s