Tutorial: Configure routing preference for a VM using the Azure CLI
This tutorial shows you how to configure routing preference for a virtual machine. Internet bound traffic from the VM will be routed via the ISP network when you choose Internet as your routing preference option. The default routing is via the Microsoft global network.
In this tutorial, you learn how to:
- Create a public IP address configured for Internet routing preference.
- Create a virtual machine.
- Verify the public IP address is set to Internet routing preference.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
- An Azure account with an active subscription. Create an account for free.
- This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
Create a resource group
An Azure resource group is a logical container into which Azure resources are deployed and managed.
Create a resource group with az group create named TutorVMRoutePref-rg in the westus2 location.
az group create \
--name TutorVMRoutePref-rg \
--location westus2
Create a public IP address
Use az network public-ip create to create a standard zone-redundant public IPv4 address named myPublicIP in TutorVMRoutePref-rg. The Tag of Internet is applied to the public IP address as a parameter in the CLI command enabling the Internet routing preference.
az network public-ip create \
--resource-group TutorVMRoutePref-rg \
--name myPublicIP \
--version IPv4 \
--ip-tags 'RoutingPreference=Internet' \
--sku Standard \
--zone 1 2 3
Create virtual machine
Use az vm create to create a virtual machine. The public IP address created in the previous section is added as part of the CLI command and is attached to the VM during creation.
az vm create \
--name myVM \
--resource-group TutorVMRoutePref-rg \
--public-ip-address myPublicIP \
--size Standard_D2a_v4 \
--image MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest \
--admin-username azureuser
Verify internet routing preference
Use az network public-ip show to verify that Internet routing preference is configured for the public IP address.
az network public-ip show \
--resource-group TutorVMRoutePref-rg \
--name myPublicIP \
--query ipTags \
--output tsv
Clean up resources
When you're done with the virtual machine and public IP address, delete the resource group and all of the resources it contains with az group delete.
az group delete \
--name TutorVMRoutePref-rg
Next steps
Advance to the next article to learn how to create a virtual machine with mixed routing preference: