Hello @secui-se-team ,
Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.
Please find the answers to your queries below:
Q1. Which one has higher priority?
- dst on-prim(1.1.1.0/24) next hop VNG (propagated by ER)
- dst on-prim(1.1.1.0/24) next hop VM1'ip (user defined)
Answer : dst on-prim(1.1.1.0/24) next hop VM1'ip (user defined) has higher priority.
If multiple routes contain the same address prefix, Azure selects the route type, based on the following priority: User-defined route > BGP route > System route.
Refer : https://video2.skills-academy.com/en-us/azure/virtual-network/virtual-networks-udr-overview#how-azure-selects-a-route
Q2. If UDR has higher priority, the longest prefix match rule is higher than it? Which one has higher priority?
- dst on-prim(1.1.1.0/24) next hop VNG (propagated by ER)
- dst on-prim(1.1.0.0/24) next hop VM1'ip (user defined)
Answer : Yes, Azure always selects a route based on LPM (longest prefix match) algorithm. Only when multiple routes contain the same address prefix, UDR will take precendence. I believe the address prefixes that you shared in this question do not overlap. But for example:
- dst on-prim(1.1.1.0/24) next hop VNG (propagated by ER)
- dst on-prim(1.1.1.0/16) next hop VM1'ip (user defined)
In this case, the BGP route advertised from ExpressRoute will be preferred.
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 routes 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, because 10.0.0.0/24 is a longer prefix than 10.0.0.0/16, even though 10.0.0.5 is within both address prefixes.
So, in conclusion the Azure routing would be as below:
LPM --> Always takes priority.
Only when multiple routes contain the same address prefix, Azure selects the route type as follows : User-defined route > BGP route > System route.
Kindly let us know if the above helped or you need further assistance on this issue.
----------------------------------------------------------------------------------------------------------------
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.