| title | Tutorial: Configure routing preference for a virtual machine |
|---|---|
| description | Learn how to create a virtual machine with a public IP address with routing preference choice using the Azure portal. |
| ms.date | 02/24/2026 |
| ms.author | mbender |
| author | mbender-ms |
| ms.service | azure-virtual-network |
| ms.subservice | ip-services |
| ms.topic | tutorial |
| ms.custom | template-tutorial |
This tutorial shows you how to configure routing preference for a virtual machine. Internet bound traffic from the virtual machine is 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:
[!div class="checklist"]
- Create a virtual machine with a public IP address configured for Internet routing preference.
- Verify the public IP address is set to Internet routing preference.
- An Azure account with an active subscription. Create an account for free.
[!INCLUDE azure-cli-prepare-your-environment-no-header.md]
- 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.
- An Azure account with an active subscription. Create an account for free.
- Azure PowerShell installed locally or Azure Cloud Shell
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run Get-Module -ListAvailable Az to find the installed version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.
-
Sign in to the Azure portal.
-
In the portal search box, enter Resource groups. In the search results, select Resource groups.
-
Select + Create.
-
In the Basics tab of Create a resource group, enter, or select the following information.
Setting Value Project details Subscription Select your subscription. Resource group Enter TutorVMRoutePref-rg. Resource details Region Select (US) West US 2. -
Select Review + create.
-
Select Create.
In this section, you create a virtual machine and public IP address in the Azure portal. During the public IP address configuration, you select Internet for routing preference.
-
In the portal search box, enter Virtual machine. In the search results, select Virtual machines.
-
In Virtual machines, select + Create, then + Virtual machine.
-
In the Basics tab of Create a virtual machine, enter, or select the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select TutorVMRoutePref-rg. Instance details Virtual machine name Enter myVM. Region Select (US) West US 2. Availability options Select No infrastructure redundancy required. Zone options Select Self-selected zone. Availability zone Select Zone 1. Security type Select Standard. Image Select Windows Server 2022 Datacenter: Azure Edition - x64 Gen2. Azure Spot instance Leave the default of unchecked. Size Select a size. Administrator account Username Enter a username. Password Enter a password. Confirm password Reenter password. Inbound port rules Public inbound ports Select None. [!NOTE] All public inbound ports are closed for this virtual machine. To manage your virtual machines, deploy Azure Bastion. For more information, see Quickstart: Deploy Azure Bastion from the Azure portal.
-
Select Next: Disks then Next: Networking, or select the Networking tab.
-
In the networking tab, enter or select the following information.
Setting Value Network interface Virtual network Leave the default of (new) TutorVMRoutePref-rg-vnet. Subnet Leave the default of (new) default (10.1.0.0/24). Public IP Select Create new.
In Name, enter myPublicIP.
In Routing preference, select Internet.
In Availability zone, select Zone 1.
Select OK. -
Select Review + create.
-
Select Create.
In this section, you create a resource group, public IP address, and virtual machine using the Azure CLI. The public IP address created in the previous section is attached to the VM during creation.
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 network security group with az network nsg create. The default rules in the network security group deny all inbound access from the internet.
az network nsg create \
--resource-group TutorVMRoutePref-rg \
--name myNSG
Note
All public inbound ports are closed for this virtual machine. To manage your virtual machines, deploy Azure Bastion. For more information, see Quickstart: Deploy Azure Bastion from the Azure portal.
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
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 \
--nsg myNSG \
--size Standard_D2a_v4 \
--image MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest \
--admin-username azureuser
In this section, you create a resource group, public IP address, and virtual machine using Azure PowerShell. The public IP address created in the previous section is attached to the VM during creation.
An Azure resource group is a logical container into which Azure resources are deployed and managed.
Create a resource group with New-AzResourceGroup named TutorVMRoutePref-rg in the westus2 location.
New-AzResourceGroup -Name 'TutorVMRoutePref-rg' -Location 'westus2'
Create a network security group with New-AzNetworkSecurityGroup. The default rules in the network security group deny all inbound access from the internet.
## Create network security group. ##
$nsg = @{
Name = 'myNSG'
ResourceGroupName = 'TutorVMRoutePref-rg'
Location = 'westus2'
}
New-AzNetworkSecurityGroup @nsg
Note
All public inbound ports are closed for this virtual machine. To manage your virtual machines, deploy Azure Bastion. For more information, see Quickstart: Deploy Azure Bastion from the Azure portal.
Use New-AzPublicIpAddress 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 PowerShell command enabling the Internet routing preference.
## Create IP tag for Internet and Routing Preference. ##
$tag = @{
IpTagType = 'RoutingPreference'
Tag = 'Internet'
}
$ipTag = New-AzPublicIpTag @tag
## Create IP. ##
$ip = @{
Name = 'myPublicIP'
ResourceGroupName = 'TutorVMRoutePref-rg'
Location = 'westus2'
Sku = 'Standard'
AllocationMethod = 'Static'
IpAddressVersion = 'IPv4'
IpTag = $ipTag
Zone = 1,2,3
}
New-AzPublicIpAddress @ip
Use New-AzVM to create a virtual machine. The public IP address created in the previous section is added as part of the PowerShell command and is attached to the VM during creation.
## Create virtual machine. ##
$vm = @{
ResourceGroupName = 'TutorVMRoutePref-rg'
Location = 'West US 2'
Name = 'myVM'
PublicIpAddressName = 'myPublicIP'
SecurityGroupName = 'myNSG'
}
New-AzVM @vm
In this section, you search for the public IP address previously created and verify the internet routing preference using the Azure portal.
-
In the portal search box, enter Public IP address. In the search results, select Public IP addresses.
-
In Public IP addresses, select myPublicIP.
-
Select Properties in Settings.
-
Verify Internet is displayed in Routing preference.
:::image type="content" source="./media/tutorial-routing-preference-virtual-machine-portal/verify-routing-preference.png" alt-text="Screenshot of verify internet routing preference.":::
In this section, you use az network public-ip show to verify that Internet routing preference is configured for the public IP address with the Azure CLI.
az network public-ip show \
--resource-group TutorVMRoutePref-rg \
--name myPublicIP \
--query ipTags \
--output tsv
In this section, you use Get-AzPublicIpAddress to verify that Internet routing preference is configured for the public IP address with Azure PowerShell.
$ip = @{
ResourceGroupName = 'TutorVMRoutePref-rg'
Name = 'myPublicIP'
}
Get-AzPublicIPAddress @ip | select -ExpandProperty IpTags
If you're not going to continue to use this application, delete the public IP address with the following steps:
-
In the search box at the top of the portal, enter Resource group.
-
In the search results, select Resource groups.
-
Select TutorVMRoutePref-rg
-
Select Delete resource group.
-
Enter myResourceGroup for TYPE THE RESOURCE GROUP NAME and select Delete.
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
When you're done with the virtual machine and public IP address, delete the resource group and all of the resources it contains with Remove-AzResourceGroup.
Remove-AzResourceGroup -Name 'TutorVMRoutePref-rg'
Advance to the next article to learn how to create a virtual machine with mixed routing preference:
[!div class="nextstepaction"] Configure both routing preference options for a virtual machine