Azure-cli: Can anyone tell me how to add a static public IP to a nic?

Created on 14 Jun 2017  路  3Comments  路  Source: Azure/azure-cli

I have this: https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-linux-cli-sample-create-vm-nsg?toc=%2fcli%2fazure%2ftoc.json

But even when the "front end" server is allocated, I didn't realize it would just get one (Does it?). The backend server they explicitly say: --public-ip-address ""

What if I have a server, and want to attach an existing static ip that I created? I can't find it any where.

Network question

Most helpful comment

Looking again at your question, if you are looking to bind an existing static public IP to an existing VM, then you would do the following:

az network nic ip-config update -g {rg} --nic-name {nic_name} -n {ip_config_name} --public-ip-address {name or ID of your static public IP}

You can use vm show to get the name of the VM's NIC and network nic show to find out the IP configuration you want to change. Alternatively, you can list the NICs for your resource group and find the one that shows as associated with your VM (one call instead of two).

All 3 comments

Hi @rlewkowicz, in the help text for VM create:

    --public-ip-address                : Name of the public IP address when creating one (default)
                                         or referencing an existing one. Can also reference an
                                         existing public IP by ID or specify "" for None.

The default behavior is to create a new (dynamic) public IP, which is why the backend VM specifies --public-ip-address "". In your case, you would specify the name (if it is in the same resource group) or ID (if it is in a different resource group) of your existing public IP. If you wanted to create the public IP as a static IP instead of dynamic, you would specify --public-ip-address-allocation static.

Does that answer your question?

Looking again at your question, if you are looking to bind an existing static public IP to an existing VM, then you would do the following:

az network nic ip-config update -g {rg} --nic-name {nic_name} -n {ip_config_name} --public-ip-address {name or ID of your static public IP}

You can use vm show to get the name of the VM's NIC and network nic show to find out the IP configuration you want to change. Alternatively, you can list the NICs for your resource group and find the one that shows as associated with your VM (one call instead of two).

Thank you!

Was this page helpful?
0 / 5 - 0 ratings