5.1.1.5. Configure User-Defined Routes
5.1.1.5. Configure User-Defined Routes
💡 First Principle: Azure already knows how to route between subnets, to peered networks, and to the internet, so it creates those routes for you. A user-defined route exists only to override that default path, most often to send traffic through a firewall that would otherwise be bypassed.
Scenario: A hub virtual network hosts Azure Firewall at 10.0.100.4. Workloads in a spoke subnet must send all internet-bound traffic through the firewall, and traffic to a decommissioned partner range must be dropped. The spoke shouldn't learn on-premises routes from the VPN gateway, because the firewall should handle that traffic too.
What It Is: Every subnet has an effective route table made of system routes that Azure creates and custom routes. Custom routes are either user-defined routes (UDRs) that you add to a route table resource, or BGP routes learned from an on-premises gateway.
System Routes Azure Creates
| Address prefix | Next hop type | Purpose |
|---|---|---|
| The virtual network's address space | Virtual network | Traffic between subnets works with no configuration |
| 0.0.0.0/0 | Internet | Anything not matched elsewhere goes to the internet |
| 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10 | None | Private ranges not in your address space are dropped |
| Peered network ranges, gateway-learned prefixes, service endpoints | Virtual network peering, Virtual network gateway, VirtualNetworkServiceEndpoint | Added only when you enable that feature |
You can't create or delete system routes, but a UDR with the same prefix overrides one.
Next Hop Types You Can Choose
- Virtual appliance: a network virtual appliance (NVA) or Azure Firewall. You also give the next hop IP address, which is the private IP of the appliance's network interface or of an internal load balancer in front of several appliances. For Azure Firewall, use the firewall's private IP.
- Virtual network gateway: sends traffic to the virtual network's gateway. It's supported only when that gateway is a VPN gateway, not ExpressRoute.
- Virtual network: keeps traffic inside the virtual network, typically to exempt a range from a broader route.
- Internet: sends the prefix to the internet explicitly.
- None: drops the traffic.
You can't choose Virtual network peering or VirtualNetworkServiceEndpoint; Azure adds those itself. A UDR's prefix can also be a service tag such as Storage, up to 25 such routes per table.
How Azure Picks a Route
- Longest prefix match wins. A 10.0.0.0/24 route beats a 10.0.0.0/16 route for 10.0.0.5, whatever their sources.
- When prefixes are identical, a UDR beats a BGP route, which beats a system route.
- Exception: system routes for the virtual network itself, peerings, and service endpoints are preferred over BGP routes even when the BGP route is more specific, and service endpoint routes can't be overridden.
Associating Route Tables
A route table is a separate resource that you associate with subnets, not virtual networks. Each subnet has zero or one route table, one table can serve many subnets, and the table must be in the same region and subscription as the virtual network. The Propagate gateway routes setting (virtual network gateway route propagation) controls whether BGP and VPN-learned routes are added to the subnets using that table; disable it to stop on-premises routes from bypassing your appliance, but never on GatewaySubnet, and don't associate a 0.0.0.0/0 route with GatewaySubnet either.
Making an Appliance Forward Traffic
A virtual machine NVA drops traffic that isn't addressed to it unless IP forwarding is enabled on its network interface in Azure, and usually inside its operating system as well. Azure Firewall needs no such setting. Put the appliance in a different subnet from the workloads it inspects, or the route can loop traffic back into the same subnet.
Practical Implementation: Force Spoke Traffic Through a Firewall with Azure CLI
# Route table that doesn't learn on-premises routes from the gateway
az network route-table create --resource-group rg-net --name rt-spoke-app \
--disable-bgp-route-propagation true
# Default route to the firewall's private IP, and a drop route for a retired range
az network route-table route create --resource-group rg-net --route-table-name rt-spoke-app \
--name default-to-firewall --address-prefix 0.0.0.0/0 \
--next-hop-type VirtualAppliance --next-hop-ip-address 10.0.100.4
az network route-table route create --resource-group rg-net --route-table-name rt-spoke-app \
--name drop-retired-partner --address-prefix 172.20.0.0/16 --next-hop-type None
# Associate the table with the workload subnet
az network vnet subnet update --resource-group rg-net --vnet-name vnet-spoke \
--name snet-app --route-table rt-spoke-app
# For a VM-based NVA instead of Azure Firewall: allow its NIC to forward traffic
az network nic update --resource-group rg-net --name nva-nic --ip-forwarding true
# Troubleshoot: effective routes on a running VM's NIC, and the next hop for one destination
az network nic show-effective-route-table --resource-group rg-net --name vm-app-nic --output table
az network watcher show-next-hop --resource-group rg-net --vm vm-app \
--source-ip 10.1.1.4 --dest-ip 8.8.8.8
Visual: Forced Tunneling Through a Firewall
⚠️ Common Pitfall: Creating a correct route table and never associating it with a subnet, or associating it with only one of several workload subnets. Check the effective routes on a VM's network interface: a route that isn't listed there isn't being used.
⚠️ Exam Trap: If a UDR for 0.0.0.0/0 points to the firewall but traffic to 10.2.1.5 still bypasses it, look for a more specific route such as a peering route for 10.2.0.0/16. Route source only breaks ties between identical prefixes; the longest prefix is evaluated first. Use Network Watcher next hop to see which route a packet actually takes.
Key Trade-Offs:
- Central inspection vs. latency and cost: Sending everything through one firewall gives a single policy point, but every flow takes an extra hop and the firewall must scale with total traffic.
- Propagation on vs. off: Leaving gateway route propagation on keeps on-premises routing automatic. Turning it off guarantees the appliance sees that traffic, but you then maintain those routes yourself.
Reflection Question: A subnet's effective routes show a UDR for 10.0.0.0/16 to an NVA and a UDR for 10.0.0.0/24 with next hop Virtual network. Which traffic from that subnet reaches the NVA, and why would an administrator build it that way?