Over a million developers have joined DZone.

PowerShell Script for Assigning Public IP Addresses to an Azure VM

DZone's Guide to

PowerShell Script for Assigning Public IP Addresses to an Azure VM

We have a look at a Powershell script that will quickly assign a public IP to your Azure VM. Check it out!

· Cloud Zone ·
Free Resource

Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.

Recently, Azure virtual machines provisioned with the 'Resource Manager/Classic' deployment model have been provisioned with virtual IP and dynamic IP addresses, but not public IP address. A public IP address is necessary for accessing services deployed on VM from a local browser.

For example, in an Azure Linux VM, if you provision Apache Hadoop/Hortonworks Data Platform/Cloudera Hadoop Distribution, you may need to access the Hadoop services from a local browser in those addresses, like the HDFS service (http://<ip address of VM>:50070 and http://<ip address of VM>:50075) and MapReduce Service (http://<ip address of VM>:8080), etc.

In order to assign public IP addresses for an Azure Linux VM , you need to execute the following PowerShell script:

Get-AzureVM -ServiceName ‘azfilestorage’ -Name ‘azfilestorage’ | Set-AzurePublicIP -PublicIPName ‘linuxvmip’ | Update-AzureVM

#Next, update the VM with SSH Port 22 so that the VM can be accessed through SSH.
Get-AzureVM -Name ‘azfilestorage’ -ServiceName ‘azfilestorage’ | Set-AzureEndpoint -Protocol tcp -Name ‘SSH’ -PublicPort 22 -LocalPort 22 | Update-AzureVM


Next, you can check the public IP address on Azure Portal under the "IP Address" section of Azure Virtual Machine:


And there you have it. Your Azure VM is now provisioned with a public IP address.

Join us in exploring application and infrastructure changes required for running scalable, observable, and portable apps on Kubernetes.

powershell ,azure ,virtual ,linux ,vm ,microsoft

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}