Configure routing preference for a public IP address using Azure CLI

This article shows you how to configure routing preference via ISP network (Internet option) for a public IP address using Azure CLI. After creating the public IP address, you can associate it with the following Azure resources for inbound and outbound traffic to the internet:

  • Virtual machine
  • Virtual machine scale set
  • Azure Kubernetes Service (AKS)
  • Internet-facing load balancer
  • Application Gateway
  • Azure Firewall

By default, the routing preference for public IP address is set to the Microsoft global network for all Azure services and can be associated with any Azure service.

If you don't have an Azure subscription, create an Azure free account before you begin.

Prerequisites

  • This article requires version 2.0.49 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.

Create a resource group

Create a resource group with the az group create command. The following example creates a resource group in the East US Azure region:

  az group create --name myResourceGroup --location eastus

Create a public IP address

Create a Public IP Address with routing preference of Internet type using command az network public-ip create, with the format as shown below.

The following command creates a new public IP with Internet routing preference in the East US Azure region.

az network public-ip create \
--name MyRoutingPrefIP \
--resource-group MyResourceGroup \
--location eastus \
--ip-tags 'RoutingPreference=Internet' \
--sku STANDARD \
--allocation-method static \
--version IPv4

Note

Currently, routing preference only supports IPV4 public IP addresses.

You can associate the above created public IP address with a Windows or Linux virtual machine. Use the CLI section on the tutorial page: Associate a public IP address to a virtual machine to associate the Public IP to your VM. You can also associate the public IP address created above with an Azure Load Balancer, by assigning it to the load balancer frontend configuration. The public IP address serves as a load-balanced virtual IP address (VIP).

Next steps