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:
- 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.
Prerequisites
- 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.
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.
Create virtual machine with a public IP address
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.
Sign in to the Azure portal.
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 Create new. Enter TutorVMRoutePref-rg. Select OK. |
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 Allow selected ports. |
Select inbound ports |
Leave the default of RDP (3389). Opening port 3389 from the internet is not recommended for production workloads. |
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
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
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.
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 New-AzResourceGroup named TutorVMRoutePref-rg in the westus2 location.
New-AzResourceGroup -Name 'TutorVMRoutePref-rg' -Location 'westus2'
Create a public IP address
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
Create virtual machine
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'
}
New-AzVM @vm
Verify internet routing preference
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.
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
Clean up resources
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'
Next steps
Advance to the next article to learn how to create a virtual machine with mixed routing preference: