Setting STATIC IP – Azure VM

When you create AZURE  VM  it sets the dynamic IP for the Virtual Machines & if you shutdown the machine the IP is reclaimed & can be assigned to other machine. This is true for public IP as well as private IP.

So how do we make sure that IP remains static even if we shutdown the VM.

Lets launch the Azure module in  PowerShell, refer my earlier Blogpost

https://techwizard.cloud/2016/10/01/azure-powershell-and-azure-command-line/

capture

Type Get-AzureVM to get the list of VMs

capture

To check the properties of any VM use the following command.

get-azurevm -ServiceName myazcloud -Name web02

capture

Azure automatically assign the IP starting from .5, I mean if you have a 10 .1.1.0 range of vm network than it will start by assigning the first VM as 10.1.1.5 & so on.

I have already assigned 10.1.1.5 as static to one of my DC’s that’s why it assigned this machine as 10.1.1.6.

To check if machine already has a static IP assigned –> use below command:

get-azurevm -ServiceName myazcloud -Name web02 | Get-AzureStaticVNetIP

capture

If result is blank that means IP assigned is static.

Now let’s update the IP to static for the web02 machine with the following command, please note that VM will reset after command is completed.

get-azurevm -ServiceName myazcloud -Name web02 | Set-AzureStaticVNetIP -IPAddress ‘10.1.1.6’ | Update-AzureVM

capture

Note the Update-AzureVM Piped command as that one is very important in azure for committing the changes.

Now lets check if the IP address is Static or not , As expected command will now return the value.

capture

If I will spun up new VM now than it will get 10.1.1.7 IP address as .5 & .6 are already set to static & this is true even if I will shutdown the machines.

Stay tuned with more Azure stuff in coming posts.

stay-mad

Regards

Sukhija Vikas

http://techwizard.cloud

 

Advertisement

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s