How to reserve IP when provisioning Azure VM (reso

2019-06-14 18:04发布

问题:

I'm provisioning a new Azure VM (resource manager) via Ubuntu command line. I'm following the steps outlined here to do so: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-tutorial/

My question is: while provisioning a new VM, what do I do on the command line to ensure it has a static IP (reserved IP)?


The same thing can be accomplished using Azure PowerShell via New-AzureReservedIP -ReservedIPName $reservedIP -Location $location

回答1:

You need to define a public IP address as part of your Resource Groupm then assign it to the correct Virtual NIC (Network Interface Card).

A public IP Address resource type represents a DNS name on the public internet. It may be used to provide a DNS name to either a virtual IP address (VIP) hosted on an Azure Load Balancer or a public instance IP address (PIP) hosted directly on a VM.

With the Azure CLI, you need to write something like this:

azure network public-ip create -g MyResourceGroup -a Dynamic -l northeurope MyPublicIP

Then you would assign your IP to the Virtual NIC of the VM. Both the VM and the NIC are part of the same resource group:

azure network nic set -g MyResourceGroup -p MyPublicIP MyNicName

You can use "azure network nic list" to get the name of the NIC.

It also seems that currently only Dynamic Public IPs are supported for being used directly on VMs (in ARM mode). Right now, static IPs can only be assigned to Load Balancer configurations. Trying to use "-a Static" spits out an error when doing "azure network nic set":

Network interface xxx references public IP address yyy with AllocationMethod property set to Static. Currently this configuration is not supported. Network interfaces can use only dynamic public IPs.

I would also like to find out when this will be supported.

edit: here is a good Azure CLI reference. You can also use -h to get command usage help.



回答2:

The term "reserve" in the question is intrinsic to a specific component in Azure (Reserved IP Addresses). So, the answer is that you CANNOT assign a reserved IP address to a VM using the resource manager model.



回答3:

Using the new portal, you don't have to do it using command line anymore. All you need to do is go create your vm from portal.azure.com and create your VM using Resource Manager Model, and then in the Settings --> Public IP Address use the Static Assignment Method and That's it! You have a static public IP that never changes.



标签: linux azure ip