Skip to content

Control hybrid path selection with route maps in Azure Route Server

Introduction


Azure Route Server uses Border Gateway Protocol (BGP) to exchange routes dynamically with network virtual appliances (NVAs) and with ExpressRoute and VPN gateways in a virtual network (VNet).


For maximum resilience, many hybrid designs combine all three connectivity options: an ExpressRoute gateway, a VPN gateway, and NVAs (typically a pair). If one path fails because of maintenance, a hardware failure, or a software bug, traffic continues over the remaining paths. However, when every path advertises the same on-premises prefixes, you need a way to decide which path Azure uses first. This article shows how Route Server route maps give you that control.


Route maps for Azure Route Server let you filter routes and change BGP attributes, such as the AS path, on the routes that Route Server learns (inbound) or advertises (outbound). You can apply them to BGP peerings with NVAs and to the ExpressRoute and VPN gateway connections.


The focus is on path selection and failover, not throughput. For simplicity, only the hub VNet is shown; the same approach applies to hub-and-spoke topologies.


The following diagram shows the reference configuration:



On-premises sites can reach the hub VNet over three independent paths:



  • ExpressRoute: a private connection through an ExpressRoute circuit and the ExpressRoute gateway, with no traffic crossing the public internet.

  • Site-to-site VPN: IPsec tunnels over the internet between the Azure VPN gateway and the on-premises VPN device or firewall.

  • NVAs: encrypted tunnels over the internet between the NVAs and the on-premises devices, using IPsec, WireGuard, or a proprietary protocol of your choice.


Route Server exchanges routes with the NVAs using BGP and integrates the routes they advertise into the VNet. Route Server also peers automatically with the ExpressRoute and VPN gateways; this peering requires no configuration. By default, however, Route Server doesn’t propagate routes between the NVAs, the ExpressRoute gateway, and the VPN gateway. To let these components learn each other’s routes, enable route exchange (the branch-to-branch setting) on Route Server.


If each path advertises different on-premises prefixes, there is nothing to choose between: each network prefix has a single path. If that path fails, its routes are withdrawn and those prefixes become unreachable from Azure.


1. Routing Preference: how Route Server chooses among paths


When Route Server is deployed and the same on-premises prefixes are advertised over multiple paths, its Routing Preference setting determines which path is preferred. The Azure portal offers three options: ExpressRoute, VPN, and AS Path.



Routing Preference controls only one direction: traffic from Azure to on-premises. Traffic from on-premises to Azure follows the routing policy configured on the on-premises devices. The rest of this article covers only the Azure-to-on-premises direction.



  • By default, Routing Preference is set to ExpressRoute: Route Server prefers routes learned from ExpressRoute regardless of AS path length, even when the VPN gateway or the NVAs advertise the same prefixes with a shorter AS path.

  • With Routing Preference set to VPN, Route Server prefers routes learned from the VPN gateway and from the NVAs over routes learned from ExpressRoute, regardless of AS path length. This option doesn’t distinguish between the VPN gateway and the NVAs: if both advertise the same prefix, Route Server selects the route with the shortest AS path.

  • With Routing Preference set to AS Path, Route Server selects the route with the shortest AS path, whichever connection it comes from. This is the option used in the rest of this article, because it lets route maps control path selection through AS path prepending.


2. Test environment


The following diagram shows the test environment used in this article:



The on-premises site, site20, advertises the prefix 10.20.0.0/24 to the hub100 VNet over three paths: ExpressRoute, the site-to-site VPN tunnels, and the tunnels to nva100-1 and nva100-2.


The hub100 VNet contains the following resources. Route Server rs1 is deployed in the same VNet, with route exchange (branch-to-branch) enabled and Routing Preference set to AS Path:


–  An ExpressRoute gateway, er-gw.


–  A VPN gateway, vpn-gw, in active-active mode with BGP enabled and ASN 65515.


–  Two NVAs, nva100-1 and nva100-2, which use ASN 100 and learn the on-premises prefix through BGP over encrypted tunnels. Each NVA establishes two BGP sessions with the Route Server rs1, one per peering IP address (primary and secondary).


2.1 Verify baseline routing


Before applying any route map, use the Azure CLI to check the routes that each gateway and Route Server learn for 10.20.0.0/24. The baseline shows why a route map is needed: with Routing Preference set to AS Path, the VPN route wins in this test environment because it has the shortest AS path.


To list the routes learned by the VPN gateway, run:


 



$sub= ‘AZURE_SUBSCRIPTION_ID’


$rg = ‘RESOURCE_GROUP_NAME’


$vpngw= ‘vpn-gw’


az network vnet-gateway list-learned-routes `


   –subscription $sub –resource-group $rg –name $vpngw `


   –output table




 


 


 


 


 


 


 


 


 


 


 


For 10.20.0.0/24, the VPN gateway prefers these two entries:


Next hop

Origin

AS path

Weight

192.168.20.2

EBgp

65020

32768

192.168.20.1

EBgp

65020

32768


The VPN gateway selects the route with the highest BGP weight, and weight is evaluated before AS path length. As a result, the routes learned directly from on-premises over the VPN tunnels (weight 32768) win over the entries learned from Route Server through 10.100.1.4 and 10.100.1.5 (weight 0), even though those entries have an empty AS path.


The output combines the route tables of the two active-active gateway instances, so each of the two VPN entries, learned from the on-premises BGP peers 192.168.20.1 and 192.168.20.2, may come from a different instance. Both entries have the same weight and the same AS path, so traffic can be load-balanced across both tunnels (equal-cost multipath, or ECMP).


Note that this is the VPN gateway’s own table, not the effective routes of Route Server rs1. The path that traffic takes from the VNet depends on the route selected by rs1, which is checked later in this section.


The routes learned by the ExpressRoute gateway show 10.20.0.0/24 with the AS path 12076-12076. Unlike the VPN and NVA paths, this AS path doesn’t include the site20 ASN 65020; for path selection, what matters is its length, 2:



$sub= ‘AZURE_SUBSCRIPTION_ID’


$rg = ‘RESOURCE_GROUP_NAME’


$ergw = ‘er-gw’


az network vnet-gateway list-learned-routes `


 –subscription $sub `


 –resource-group $rg `


 –name $ergw `


 –output table




 


 


 


 


 


To list the routes that Route Server learns from the NVAs, run the following command for nva100-1; repeat it with –name nva100-2 for the second NVA. The query returns the routes that Route Server learned from nva100-1:



$sub = ‘AZURE_SUBSCRIPTION_ID’


$rg = ‘RESOURCE_GROUP_NAME’


$routeserver = ‘rs1’


$q=”RouteServiceRole_IN_0[].{Prefix:network,NextHop:nextHop,SourcePeer:sourcePeer,ASPath:asPath,Weight:weight}”


az network routeserver peering list-learned-routes `


 –subscription $sub `


 –resource-group $rg `


 –routeserver $routeserver `


 –name nva100-1 `


 –query $q `


 –output table




 


 


 


The outputs show the Route Server receives 10.20.0.0/24 from three sources, each with a different AS path:



  • ExpressRoute (er-gw): AS path {12076, 12076}, length 2

  • VPN gateway (vpn-gw): AS path {65020}, length 1

  • NVAs (nva100-1 and nva100-2): AS path {100, 65020}, length 2


With Routing Preference set to AS Path, the VPN route wins because it has the shortest AS path, while ExpressRoute and the NVAs tie at length 2. The effective routes of Route Server confirm that the VPN gateway is the next hop for 10.20.0.0/24:



You can retrieve the same effective routes with the Azure CLI:



$sub= ‘AZURE_SUBSCRIPTION_ID’


$rg = ‘RESOURCE_GROUP_NAME’


$routeserver = ‘rs1’


$q= “value[].{addressPrefixes:join(‘, ‘,addressPrefixes),asPath:asPath,nextHopType:nextHopType,nextHops:join(‘, ‘,nextHops)}” az network vhub get-effective-routes `


 –subscription $sub `


 –resource-group $rg `


 –name $routeServer `


 –query $q `


 –output table




 


 


 


 


3. Create a custom routing policy in the VNet


The goal is to create a custom routing policy in the Azure VNet that sets an order of priority in path selection:



  • ExpressRoute is the preferred path.

  • The site-to-site VPN path is used when the ExpressRoute path is unavailable.

  • The NVA paths are used when both the ExpressRoute and VPN paths are unavailable.


This order is only an example; you can apply any priority sequence that fits your architecture requirements. When you prepend, don’t use ASNs reserved by Azure: the public ASNs 8074, 8075, and 12076, and the private ASNs 65515, 65517, 65518, 65519, and 65520.


To enforce this order, apply inbound route maps that use AS path prepending, which adds copies of an ASN to the AS path so that BGP treats the route as less preferred. Each route map lengthens the AS path of 10.20.0.0/24 as Route Server receives it from a connection, giving every path a different AS path length:



  • ExpressRoute: no route map needed. The AS path remains {12076, 12076} (length 2).

  • Site-to-site VPN: an inbound route map on the VPN connection prepends AS 65020 twice. The AS path becomes {65020, 65020, 65020} (length 3).

  • NVAs: an inbound route map on the nva100-1 and nva100-2 connections prepends AS 100 twice. The AS path becomes {100, 100, 100, 65020} (length 4).



The following diagram shows the three paths from a workload in the VNet to on-premises, numbered 1, 2, and 3 for reference in the rest of this section:




  • Path 1 (primary): Preferred because it has the shortest AS path.

  • Path 2 (secondary): Used only if Path 1 is unavailable.

  • Path 3 (tertiary): Used only if both Path 1 and Path 2 are unavailable.


3.1 Prepend the AS path on the VPN connection (inbound)


Now add a route map, rmap-vpn-in, that prepends the AS path on the VPN connection.



Add a rule to the route map rmap-vpn-in that prepends AS 65020 twice (Value: 65020,65020) to the routes received from the VPN gateway:



Before applying the route map, the Connections Dashboard shows the routes that Route Server receives from the VPN connections:



After you apply rmap-vpn-in in the inbound direction to the VPN gateway connection, the Connections Dashboard shows 10.20.0.0/24 with the longer AS path {65020, 65020, 65020}:



 


3.2 Prepend the AS path on the NVA connections (inbound)


The route map for the NVAs has not yet been applied. The Connections dashboard shows the routes that Route Server receives from the NVAs:



Create an inbound route map for the NVA connections, with a rule that prepends AS 100 twice (value 100,100) to the routes received from nva100-1 and nva100-2:



Apply the route map in the inbound direction to the BGP peerings with nva100-1 and nva100-2:



 


3.3 Verify routing with the route maps applied


As expected, the ExpressRoute connection advertises the on-premises network with an AS path length of 2:



 


The Connections dashboard now shows the route to the on-premises network from the VPN connection with an AS path length of 3. The VPN gateway still advertises a length of 1; the two extra ASNs are added by the inbound route map as Route Server receives the route:



As expected, the NVA connections advertise the on-premises network with an AS path length of 4:



Route Server now selects the ExpressRoute path, which has the shortest AS path (length 2), as the next hop to 10.20.0.0/24. To confirm it, check the effective routes of rs1 again, in the Azure portal or with the Azure CLI command in section 2.1: the next hop for 10.20.0.0/24 should now be the ExpressRoute gateway instead of the VPN gateway. If ExpressRoute fails, its route is withdrawn and the VPN path (length 3) takes over; if the VPN path also fails, the NVAs (length 4) take over. When a higher-priority path recovers, its shorter AS path makes it preferred again. Test both failover and recovery before you rely on this policy in production.


 


4. Summary


With Routing Preference set to AS Path, inbound route maps that prepend the AS path let you set a path priority for traffic from Azure to on-premises. Key points to remember:



  • Set Routing Preference to AS Path so that AS path length decides which path Route Server prefers.

  • Verify path selection in the effective routes of Route Server, not in the learned routes of each gateway, because each gateway applies its own BGP weights.

  • Use inbound route maps to prepend the AS path and set the priority. The ExpressRoute, VPN, NVA order used here is only an example; adjust the prepend lengths to match your own priorities.

  • This custom routing policy is local to the Azure VNet: it changes only how Route Server selects routes for traffic from Azure to on-premises, and it isn’t propagated to on-premises. To avoid asymmetric routing, which stateful firewalls on either side can drop, configure the on-premises devices to prefer the same path order for traffic toward Azure, for example with BGP local preference.


5. Next steps


Microsoft Tech Community originally posted this article on 23 November 2026 at 1:58 PM.

Leave a Reply