Azure virtual network traffic routing

rw-book-cover

In this article

  1. System routes
  2. Custom routes
  3. Next hop types across Azure tools
  4. How Azure selects a route
  5. 0.0.0.0/0 address prefix
  6. Routing example
  7. Next steps

Learn about how Azure routes traffic between Azure, on-premises, and Internet resources. Azure automatically creates a route table for each subnet within an Azure virtual network and adds system default routes to the table. To learn more about virtual networks and subnets, see Virtual network overview. You can override some of Azure's system routes with custom routes, and add more custom routes to route tables. Azure routes outbound traffic from a subnet based on the routes in a subnet's route table.

System routes

Azure automatically creates system routes and assigns the routes to each subnet in a virtual network. You can't create system routes, nor can you remove system routes, but you can override some system routes with custom routes. Azure creates default system routes for each subnet, and adds more optional default routes to specific subnets, or every subnet, when you use specific Azure capabilities.

Default

Each route contains an address prefix and next hop type. When traffic leaving a subnet is sent to an IP address within the address prefix of a route, the route that contains the prefix is the route Azure uses. Learn more about how Azure selects a route when multiple routes contain the same prefixes, or overlapping prefixes. Whenever a virtual network is created, Azure automatically creates the following default system routes for each subnet within the virtual network:

Source Address prefixes Next hop type
Default Unique to the virtual network Virtual network
Default 0.0.0.0/0 Internet
Default 10.0.0.0/8 None
Default 172.16.0.0/12 None
Default 192.168.0.0/16 None
Default 100.64.0.0/10 None

The next hop types listed in the previous table represent how Azure routes traffic destined for the address prefix listed. Explanations for the next hop types follow:

Optional default routes

Azure adds more default system routes for different Azure capabilities, but only if you enable the capabilities. Depending on the capability, Azure adds optional default routes to either specific subnets within the virtual network, or to all subnets within a virtual network. The other system routes and next hop types that Azure may add when you enable different capabilities are:

Source Address prefixes Next hop type Subnet within virtual network that route is added to
Default Unique to the virtual network, for example: 10.1.0.0/16 VNet peering All
Virtual network gateway Prefixes advertised from on-premises via BGP, or configured in the local network gateway Virtual network gateway All
Default Multiple VirtualNetworkServiceEndpoint Only the subnet a service endpoint is enabled for.

The VNet peering and VirtualNetworkServiceEndpoint next hop types are only added to route tables of subnets within virtual networks created through the Azure Resource Manager deployment model. The next hop types aren't added to route tables that are associated to virtual network subnets created through the classic deployment model. Learn more about Azure deployment models.

Custom routes

You create custom routes by either creating user-defined routes, or by exchanging border gateway protocol (BGP) routes between your on-premises network gateway and an Azure virtual network gateway.

User-defined

You can create custom, or user-defined(static), routes in Azure to override Azure's default system routes, or to add more routes to a subnet's route table. In Azure, you create a route table, then associate the route table to zero or more virtual network subnets. Each subnet can have zero or one route table associated to it. To learn about the maximum number of routes you can add to a route table and the maximum number of user-defined route tables you can create per Azure subscription, see Azure limits. When you create a route table and associate it to a subnet, the table's routes are combined with the subnet's default routes. If there are conflicting route assignments, user-defined routes override the default routes.

You can specify the following next hop types when creating a user-defined route:

You can't specify Virtual network peering or VirtualNetworkServiceEndpoint as the next hop type in user-defined routes. Routes with the Virtual network peering or VirtualNetworkServiceEndpoint next hop types are only created by Azure, when you configure a virtual network peering, or a service endpoint.

Service Tags for user-defined routes

You can now specify a service tag as the address prefix for a user-defined route instead of an explicit IP range. A service tag represents a group of IP address prefixes from a given Azure service. Microsoft manages the address prefixes encompassed by the service tag and automatically updates the service tag as addresses change. Thus minimizing the complexity of frequent updates to user-defined routes and reducing the number of routes you need to create. You can currently create 25 or less routes with service tags in each route table. With this release, using service tags in routing scenarios for containers is also supported.

Exact Match

The system gives preference to the route with the explicit prefix when there's an exact prefix match between a route with an explicit IP prefix and a route with a Service Tag. When multiple routes with Service Tags have matching IP prefixes, routes are evaluated in the following order:

  1. Regional tags (for example, Storage.EastUS, AppService.AustraliaCentral)
  2. Top level tags (for example, Storage, AppService)
  3. AzureCloud regional tags (for example, AzureCloud.canadacentral, AzureCloud.eastasia)
  4. The AzureCloud tag

To use this feature, specify a Service Tag name for the address prefix parameter in route table commands. For example, in PowerShell you can create a new route to direct traffic sent to an Azure Storage IP prefix to a virtual appliance by using:

Azure PowerShell

$param = @{
    Name = 'StorageRoute'
    AddressPrefix = 'Storage'
    NextHopType = 'VirtualAppliance'
    NextHopIpAddress = '10.0.100.4'
}
New-AzRouteConfig @param



The same command for CLI is as follows:

Azure CLI

az network route-table route create \
    --resource-group MyResourceGroup \
    --route-table-name MyRouteTable \
    --name StorageRoute \
    --address-prefix Storage \
    --next-hop-type VirtualAppliance \
    --next-hop-ip-address 10.0.100.4


Next hop types across Azure tools

The name displayed and referenced for next hop types is different between the Azure portal and command-line tools, and the Azure Resource Manager and classic deployment models. The following table lists the names used to refer to each next hop type with the different tools and deployment models:

Next hop type Azure CLI and PowerShell (Resource Manager) Azure classic CLI and PowerShell (classic)
Virtual network gateway VirtualNetworkGateway VPNGateway
Virtual network VNetLocal VNETLocal (not available in the classic CLI in Service Management mode)
Internet Internet Internet (not available in the classic CLI in Service Management mode)
Virtual appliance VirtualAppliance VirtualAppliance
None None Null (not available in the classic CLI in Service Management mode)
Virtual network peering VNet peering Not applicable
Virtual network service endpoint VirtualNetworkServiceEndpoint Not applicable
Border gateway protocol

An on-premises network gateway can exchange routes with an Azure virtual network gateway using the border gateway protocol (BGP). Using BGP with an Azure virtual network gateway is dependent on the type you selected when you created the gateway:

When you exchange routes with Azure using BGP, a separate route is added to the route table of all subnets in a virtual network for each advertised prefix. The route is added with Virtual network gateway listed as the source and next hop type.

ER and VPN Gateway route propagation can be disabled on a subnet using a property on a route table. When you disable route propagation, the system doesn't add routes to the route table of all subnets with Virtual network gateway route propagation disabled. This process applies to both static routes and BGP routes. Connectivity with VPN connections is achieved using custom routes with a next hop type of Virtual network gateway. Route propagation shouldn't be disabled on the GatewaySubnet. The gateway will not function with this setting disabled. For details, see How to disable Virtual network gateway route propagation.

How Azure selects a route

When outbound traffic is sent from a subnet, Azure selects a route based on the destination IP address, using the longest prefix match algorithm. For example, a route table has two routes: One route specifies the 10.0.0.0/24 address prefix, while the other route specifies the 10.0.0.0/16 address prefix. Azure directs traffic destined for 10.0.0.5 to the next hop type specified in the route with the 10.0.0.0/24 address prefix. This process occurs because 10.0.0.0/24 is a longer prefix than 10.0.0.0/16, even though 10.0.0.5 falls within both address prefixes. Azure directs traffic destined for 10.0.1.5 to the next hop type specified in the route with the 10.0.0.0/16 address prefix. This process occurs because 10.0.1.5 isn't included in the 10.0.0.0/24 address prefix, making the route with the 10.0.0.0/16 address prefix the longest matching prefix.

If multiple routes contain the same address prefix, Azure selects the route type, based on the following priority:

  1. User-defined route
  2. BGP route
  3. System route

Note

System routes for traffic related to virtual network, virtual network peerings, or virtual network service endpoints, are preferred routes, even if BGP routes are more specific.

For example, a route table contains the following routes:

Source Address prefixes Next hop type
Default 0.0.0.0/0 Internet
User 0.0.0.0/0 Virtual network gateway

When traffic is destined for an IP address outside the address prefixes of any other routes in the route table, Azure selects the route with the User source, because user-defined routes are higher priority than system default routes.

See Routing example for a comprehensive routing table with explanations of the routes in the table.

0.0.0.0/0 address prefix

A route with the 0.0.0.0/0 address prefix gives instructions to Azure. Azure uses these instructions to route traffic destined for an IP address that doesn't fall within the address prefix of any other route in a subnet's route table. When a subnet is created, Azure creates a default route to the 0.0.0.0/0 address prefix, with the Internet next hop type. If you don't override this route, Azure routes all traffic destined to IP addresses not included in the address prefix of any other route, to the Internet. The exception is that traffic to the public IP addresses of Azure services remains on the Azure backbone network, and isn't routed to the Internet. When you override this route with a custom route, traffic destined for addresses not within the address prefixes of any other route in the route table is directed. The destination depends on whether you specify a network virtual appliance or virtual network gateway in the custom route.

When you override the 0.0.0.0/0 address prefix, not only does outbound traffic from the subnet flow through the virtual network gateway or virtual appliance, but the following changes also occur with Azure's default routing:

If your virtual network is connected to an Azure VPN gateway, don't associate a route table to the gateway subnet that includes a route with a destination of 0.0.0.0/0. Doing so can prevent the gateway from functioning properly. For details, see the Why are certain ports opened on my VPN gateway? question in the VPN Gateway FAQ.

See DMZ between Azure and your on-premises datacenter for implementation details when using virtual network gateways between the Internet and Azure.

Routing example

To illustrate the concepts in this article, the sections that follow describe:

Note

This example isn't intended to be a recommended or best practice implementation. Rather, it is provided only to illustrate concepts in this article.

Requirements
  1. Implement two virtual networks in the same Azure region and enable resources to communicate between the virtual networks.

  2. Enable an on-premises network to communicate securely with both virtual networks through a VPN tunnel over the Internet. Alternatively, an ExpressRoute connection could be used, but in this example, a VPN connection is used.

  3. For one subnet in one virtual network:

    • Force all outbound traffic from the subnet, except to Azure Storage and within the subnet, to flow through a network virtual appliance, for inspection and logging.
    • Don't inspect traffic between private IP addresses within the subnet; allow traffic to flow directly between all resources.
    • Drop any outbound traffic destined for the other virtual network.
    • Enable outbound traffic to Azure storage to flow directly to storage, without forcing it through a network virtual appliance.
  4. Allow all traffic between all other subnets and virtual networks.

Implementation

The following picture shows an implementation through the Azure Resource Manager deployment model that meets the previous requirements:

Diagram of network.
Arrows show the flow of traffic.

Route tables
Subnet1

The route table for Subnet1 in the picture contains the following routes:

ID Source State Address prefixes Next hop type Next hop IP address User-defined route name
1 Default Invalid 10.0.0.0/16 Virtual network
2 User Active 10.0.0.0/16 Virtual appliance 10.0.100.4 Within-VNet1
3 User Active 10.0.0.0/24 Virtual network Within-Subnet1
4 Default Invalid 10.1.0.0/16 VNet peering
5 Default Invalid 10.2.0.0/16 VNet peering
6 User Active 10.1.0.0/16 None ToVNet2-1-Drop
7 User Active 10.2.0.0/16 None ToVNet2-2-Drop
8 Default Invalid 10.10.0.0/16 Virtual network gateway [X.X.X.X]
9 User Active 10.10.0.0/16 Virtual appliance 10.0.100.4 To-On-Prem
10 Default Active [X.X.X.X] VirtualNetworkServiceEndpoint
11 Default Invalid 0.0.0.0/0 Internet
12 User Active 0.0.0.0/0 Virtual appliance 10.0.100.4 Default-NVA

An explanation of each route ID follows:

Subnet2

The route table for Subnet2 in the picture contains the following routes:

Source State Address prefixes Next hop type Next hop IP address
Default Active 10.0.0.0/16 Virtual network
Default Active 10.1.0.0/16 Virtual network peering
Default Active 10.2.0.0/16 Virtual network peering
Default Active 10.10.0.0/16 Virtual network gateway [X.X.X.X]
Default Active 0.0.0.0/0 Internet
Default Active 10.0.0.0/8 None
Default Active 100.64.0.0/10 None
Default Active 192.168.0.0/16 None

The route table for Subnet2 contains all Azure-created default routes and the optional virtual network peering and virtual network gateway optional routes. Azure added the optional routes to all subnets in the virtual network when the gateway and peering were added to the virtual network. Azure removed the routes for the 10.0.0.0/8, 192.168.0.0/16, and 100.64.0.0/10 address prefixes from the Subnet1 route table when the user-defined route for the 0.0.0.0/0 address prefix was added to Subnet1.

Next steps