Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

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

PS


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

IP-addr


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

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
powershell ,azure ,virtual ,linux ,vm ,microsoft

Published at DZone with permission of Anindita Basak, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}