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!
Join the DZone community and get the full member experience.Join For Free
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.
Published at DZone with permission of Anindita Basak, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.