As far as I can tell, this behavior likely stems from the route selection precedence in Azure's routing infrastructure. Azure follows specific rules when evaluating and selecting routes, and while longest prefix match is one criterion, other factors may override it.
This includes the following:
- Route Type Precedence Azure uses a hierarchy for route selection, where system-defined routes (like those for ExpressRoute) take precedence over user-defined routes (UDRs) for the same destination, even if the UDR has a longer prefix match.
- ExpressRoute Prefix Advertisement
The BGP route for
172.16.1.0/32
advertised via ExpressRoute might be prioritized over the IPsec VPN route because:- ExpressRoute is a Microsoft-managed route, and Azure treats these routes as higher precedence compared to custom IPsec routes.
- Traffic selectors in IPsec VPN are typically only used to establish the tunnel and are not actively enforced for routing decisions in Azure unless explicitly configured.
- Overlapping Prefixes
- You mention that IPsec is using
172.16.1.240/32
while ExpressRoute advertises172.16.1.0/32
. If the system route for172.16.1.0/32
via ExpressRoute exists, it might override the longer prefix match of172.16.1.240/32
due to route type precedence.
- You mention that IPsec is using
- Traffic Selector Scope Traffic selectors do not directly impact Azure's route selection; they only negotiate which traffic is allowed to pass through the IPsec tunnel. If Azure's routing table directs traffic via ExpressRoute, it will bypass the tunnel, regardless of the selectors.
To address this, you might consider the following:
Option 1: Use a User-Defined Route (UDR)
- Create a UDR for the Azure subnets that need to communicate with the on-prem network.
- Add a UDR with the destination
172.16.1.240/32
(or other specific prefixes for on-prem) and specify the virtual network gateway (used for the IPsec tunnel) as the next hop. - Associate the UDR with the subnets where the spoke resources are deployed.
Option 2: Advertise More Specific Prefixes via IPsec
If possible, configure the on-premises side of the IPsec VPN to advertise the specific prefix 172.16.1.240/32
instead of or in addition to 172.16.1.0/32
. This ensures the IPsec route is considered a better match by Azure's routing logic.
Option 3: Adjust ExpressRoute Advertisements
- If you can, stop advertising
172.16.1.0/32
via BGP over ExpressRoute. This will force Azure to route traffic for172.16.1.240/32
through the IPsec tunnel.
Option 4: Configure BGP for the IPsec VPN Enabling BGP for the IPsec VPN allows you to advertise routes dynamically. Azure will evaluate all routes and prioritize based on longest prefix match and route type precedence.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin