User-Defined Routes
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Module: Design and Implement Hybrid Networking
Section: Hybrid Routing
Lesson: User-Defined Routes (UDRs)
Introduction: The Fundamentals of Traffic Control
In a standard cloud networking environment, the platform automatically manages routing tables. When you create a virtual network (VNet) or a Virtual Private Cloud (VPC), the system creates default routes that allow resources within the same network to talk to each other and, if configured, reach the public internet. However, as your infrastructure grows—particularly when you move into hybrid environments—these default behaviors often fall short. You inevitably reach a point where you need to force traffic through a specific security appliance, inspect traffic between subnets, or direct traffic through a site-to-site VPN tunnel rather than the default gateway.
This is where User-Defined Routes (UDRs), sometimes called custom routes, become essential. UDRs allow you to override the platform’s default system routes. By defining your own routing logic, you gain granular control over the path a packet takes from a source to a destination. In a hybrid networking scenario, this is the mechanism that allows you to steer traffic from your cloud workloads toward your on-premises data center via a dedicated gateway or a firewall virtual appliance. Mastering UDRs is not just about connectivity; it is about security, compliance, and traffic optimization.
Understanding the Routing Hierarchy
Before diving into the "how-to," it is vital to understand how cloud providers prioritize routes. Routing is not a free-for-all; it follows a strict hierarchy. If you have a system route that says "go to the internet" and a user-defined route that says "go to the firewall," the system must know which one to honor.
Generally, the priority order is as follows:
- User-Defined Routes (UDRs): These take the highest precedence. If you define a route, the system will use it regardless of what the system default is.
- BGP Routes: If you are using a dynamic routing protocol like Border Gateway Protocol (BGP) to connect your cloud to your on-premises network, these routes are processed after UDRs.
- System Default Routes: These are the fallback routes provided by the cloud platform. They are only used if no UDR or BGP route matches the traffic destination.
Callout: The "Longest Prefix Match" Rule Regardless of the priority hierarchy, all routing protocols and systems follow the "longest prefix match" rule. If you have a route for 10.0.0.0/16 and another for 10.0.1.0/24, a packet destined for 10.0.1.5 will always use the 10.0.1.0/24 route because it is more specific. Always remember that specificity trumps general priority when multiple routes for the same destination exist in the same table.
The Anatomy of a User-Defined Route
A User-Defined Route consists of two primary components: the Address Prefix and the Next Hop. The Address Prefix is the destination CIDR block (e.g., 192.168.1.0/24). The Next Hop defines where the packet should be sent when it matches that prefix.
Common "Next Hop" types include:
- Virtual Appliance: Traffic is sent to a specific IP address of a virtual machine (usually a firewall or a load balancer).
- Virtual Network Gateway: Traffic is sent to a VPN or ExpressRoute gateway.
- Internet: Traffic is sent directly to the public internet, bypassing internal gateways.
- None: Traffic is dropped (often used for blackholing malicious or unwanted traffic).
- Virtual Network: Traffic stays within the local network.
Practical Example: The Hub-and-Spoke Firewall
In a typical hybrid design, you might have a "Hub" virtual network that contains your security appliances and your connection to the on-premises network. You have "Spoke" virtual networks where your application servers live. Without UDRs, a server in the Spoke would try to talk directly to the internet. By applying a UDR to the Spoke subnet, you can force all traffic destined for 0.0.0.0/0 (the internet) to go to the internal IP address of a firewall in the Hub.
Implementing UDRs: Step-by-Step
Implementing UDRs involves creating a route table, adding specific routes, and then associating that table with one or more subnets. Here is how you approach this process using common cloud CLI patterns.
Step 1: Create the Route Table
The route table is a container for your rules. It does nothing until it is associated with a subnet.
# Example command to create a route table
az network route-table create \
--name MyCustomRouteTable \
--resource-group MyResourceGroup \
--location eastus
Step 2: Add a Route
Now, you add the specific instruction. Let's say we want to route all traffic for our on-premises network (10.50.0.0/16) through a virtual appliance (Firewall) located at 10.0.0.5.
# Example command to add a route
az network route-table route create \
--resource-group MyResourceGroup \
--route-table-name MyCustomRouteTable \
--name ToOnPremises \
--address-prefix 10.50.0.0/16 \
--next-hop-type VirtualAppliance \
--next-hop-ip-address 10.0.0.5
Step 3: Associate the Route Table with a Subnet
The routes are inactive until you bind them to a subnet. Once associated, every resource in that subnet will immediately begin using these rules.
# Example command to associate with a subnet
az network vnet subnet update \
--resource-group MyResourceGroup \
--vnet-name MyVNet \
--name MySubnet \
--route-table MyCustomRouteTable
Common Pitfalls and Troubleshooting
Even experienced engineers run into issues with UDRs because routing is inherently invisible until it breaks. When traffic stops flowing, it is often because of a misconfigured route or an asymmetric routing issue.
Asymmetric Routing
Asymmetric routing occurs when traffic leaves a server via one path (e.g., through a firewall) but returns via a different path (e.g., directly to the server). Many firewalls and stateful security devices will drop these return packets because they never saw the original request.
- How to avoid: Ensure that your return traffic is forced through the same appliance or that you have configured your appliances to handle asynchronous traffic if necessary. Often, the best solution is to ensure symmetry in your route tables across both sides of the connection.
Overlapping Prefixes
If you create a UDR for 10.0.0.0/8 and then create another for 10.1.0.0/16, the system will use the more specific route for the 10.1.x.x range. However, if you accidentally create two routes with the exact same prefix, the deployment will fail. Always audit your routing table using CLI tools or the portal to ensure there are no conflicting overlaps.
Missing "Next Hop" Availability
If your "Next Hop" is an appliance, and that appliance goes down, your traffic will be blackholed. The cloud platform does not automatically "failover" the route just because the destination IP is unreachable.
- Tip: If you are using virtual appliances, ensure they are deployed in a High Availability (HA) pair with a load balancer in front. The "Next Hop" should be the IP address of the load balancer, not the individual firewall instance.
Best Practices for Hybrid Routing
Managing routes in a large, hybrid environment can become a nightmare if not documented and standardized. Follow these industry-standard practices to maintain a clean environment.
- Use Descriptive Names: Do not name your routes "Route1" or "TestRoute." Use a naming convention that describes the destination and the next hop, such as
To-OnPrem-via-FirewallorInternet-via-Proxy. - Document Everything: Keep a central registry of all UDRs. Since UDRs are not always visible in a single global view, having a spreadsheet or a configuration management database (CMDB) is vital for troubleshooting.
- Minimize UDR Count: While you can have many routes, performance can degrade if you have thousands of individual routes on a single subnet. Where possible, summarize your routes into larger CIDR blocks.
- Implement Infrastructure as Code (IaC): Never manually configure UDRs in production. Use Terraform, Bicep, or CloudFormation. This ensures that your routing configuration is version-controlled and can be audited.
Callout: UDRs vs. BGP A common question is: "Should I use UDRs or BGP for my hybrid network?" The answer depends on scale. BGP is dynamic and handles route propagation automatically, making it ideal for large, changing environments. UDRs are static and manual, making them better for specific, localized traffic steering (like forcing traffic through a security appliance). Use BGP for global connectivity and UDRs for specific "exception" routing.
Comparison Table: Routing Methods
| Feature | System Routes | User-Defined Routes | BGP Routes |
|---|---|---|---|
| Creation | Automatic | Manual | Dynamic (via Gateway) |
| Priority | Lowest | Highest | Medium |
| Flexibility | None | High | High |
| Maintenance | None | Manual | Automatic |
| Best Use Case | Basic connectivity | Security/Inspection | Hybrid/Multi-site |
Deep Dive: Handling "Force Tunneling"
A very common hybrid networking requirement is "force tunneling," where all traffic from the cloud must be inspected by an on-premises security stack before reaching the internet. This is a classic UDR use case.
The Workflow
- The Gateway: You establish a VPN or ExpressRoute connection.
- The Route: You create a UDR on your cloud subnets with a
0.0.0.0/0prefix. - The Next Hop: You set the next hop to the Virtual Network Gateway.
- The On-Premises Return: You must ensure your on-premises edge router is configured to accept this traffic and route it out to the internet, or loop it back into a proxy.
Warning: If you enable force tunneling without having a valid path for that traffic on-premises, you will effectively disconnect your cloud instances from the internet. Always test this in a non-production subnet first.
Advanced Configuration: The "None" Next Hop
Sometimes, you want to explicitly prevent traffic from reaching a destination. While Network Security Groups (NSGs) are the standard way to block traffic, UDRs can be used to "blackhole" traffic. By setting the next hop to None, you essentially tell the router to discard the packet. This is useful in scenarios where you want to ensure that specific internal traffic cannot reach the internet, even if an NSG rule is accidentally deleted or misconfigured. This provides an additional layer of "defense in depth."
Handling Routing Changes and Troubleshooting
When you modify a route, the change is typically instantaneous. However, cached connections might not immediately respect the new route. If you change a route for an existing, long-running connection (like a database sync), that session may stay on the old path until it times out or is reset.
Troubleshooting Steps
- Check the Effective Routes: Most cloud platforms provide an "Effective Routes" view on a network interface. Always check this first. It shows you the actual result of all your UDRs, BGP routes, and system routes combined.
- Use Network Watcher/Connectivity Checks: Use built-in diagnostic tools to perform a "Next Hop" test. This tells you exactly where the platform thinks a packet destined for a specific IP will go.
- Verify the Next Hop Reachability: If your UDR points to a virtual appliance, check if that appliance is actually reachable. If the appliance is down, the route is effectively a dead end.
- Look for Asymmetry: Use packet captures on both the source and the destination to see if the return path is different from the request path.
Summary of Key Concepts
- Precedence: UDRs override system routes. Always verify your route table priority to ensure your custom rules are actually being applied.
- Granularity: Use the longest prefix match rule to your advantage. You can create specific routes for sensitive subnets while leaving general traffic to the default gateway.
- Next Hop Awareness: The "Next Hop" must be a stable, reachable entity. If it is an appliance, use a load balancer to ensure high availability.
- IaC is Mandatory: Routing is foundational infrastructure. Managing it through manual clicks in a portal leads to "configuration drift" and human error. Use Terraform or similar tools to define your routes as code.
- Asymmetric Awareness: Always remember that traffic needs a return path. A UDR that sends traffic "out" via a firewall must be paired with routing logic that ensures the "in" traffic also passes through that same firewall.
- Effective Routes: Never guess what your routing table looks like. Use the "Effective Routes" diagnostic tool provided by your cloud provider to see the final, computed state of your networking stack.
Frequently Asked Questions (FAQ)
Q: Can I have multiple UDRs for the same subnet? A: Yes, you can have a table with many routes. The system will evaluate them against the destination IP and apply the most specific match.
Q: Does a UDR affect traffic between subnets in the same VNet? A: Yes, if you define a route for the VNet range, it will override the default system route. However, be careful here; if you misconfigure this, you can easily break internal communication between your own servers.
Q: What happens if I delete a route table? A: If you delete a route table that is currently associated with a subnet, the association is removed, and the subnet will immediately revert to using the system default routes. This can cause a sudden, unexpected change in traffic patterns.
Q: Can I route traffic to an IP address that is not in my network? A: Yes, but the next hop must be reachable. If you point a route to an IP address that the network infrastructure cannot resolve or reach (e.g., an IP on the other side of a VPN that isn't connected), the traffic will be dropped.
Q: Is there a limit to how many routes I can have? A: Every cloud provider has a limit on the number of routes per route table and the number of route tables per subscription. Always check the service quotas for your specific cloud provider before designing highly complex, distributed routing tables.
Conclusion
User-Defined Routes are the "steering wheel" of your cloud network. While the cloud provider gives you a default path, UDRs allow you to take control, ensuring traffic flows through the necessary security inspection points, hybrid gateways, and optimized paths required by your business. By understanding the hierarchy of routing, the importance of the longest prefix match, and the necessity of infrastructure-as-code, you can build a network that is not only functional but also secure and manageable.
As you move forward, treat your routing tables as living documents. Audit them regularly, test changes in isolated environments, and always prioritize simplicity over complexity. A clean, well-documented routing architecture is the hallmark of a mature cloud engineering practice. Use these tools wisely, and you will find that even the most complex hybrid network scenarios become straightforward to manage and scale.
Reach the last section to complete this lesson and earn points — you're on section 1 of 11.
- Introduction to Azure Networking
- Introduction to Azure Networking Quiz5q
- Virtual Network Address Spaces
- Virtual Network Address Spaces Quiz5q
- Subnet Design and Configuration
- Subnet Design and Configuration Quiz5q
- Public and Private IP Addressing
- Public and Private IP Addressing Quiz5q
- Network Interface Configuration
- Network Interface Configuration Quiz5q
- Azure DNS Configuration
- Azure DNS Configuration Quiz5q
- Virtual Network Peering
- Virtual Network Peering Quiz5q
- Global VNet Peering
- Global VNet Peering Quiz5q
- Azure Virtual WAN
- Azure Virtual WAN Quiz5q
- Virtual WAN Hub Configuration
- Virtual WAN Hub Configuration Quiz5q
- Service Chaining and UDR
- Service Chaining and UDR Quiz5q
- Network Virtual Appliances
- Network Virtual Appliances Quiz5q
- Azure VPN Gateway Overview
- Azure VPN Gateway Overview Quiz5q
- Site-to-Site VPN Configuration
- Site-to-Site VPN Configuration Quiz5q
- Point-to-Site VPN Configuration
- Point-to-Site VPN Configuration Quiz5q
- VPN Gateway SKUs and Sizing
- VPN Gateway SKUs and Sizing Quiz5q
- VPN Gateway High Availability
- VPN Gateway High Availability Quiz5q
- VPN Gateway Troubleshooting
- VPN Gateway Troubleshooting Quiz5q
- ExpressRoute Overview
- ExpressRoute Overview Quiz5q
- ExpressRoute Circuit Configuration
- ExpressRoute Circuit Configuration Quiz5q
- ExpressRoute Peering Types
- ExpressRoute Peering Types Quiz5q
- ExpressRoute Global Reach
- ExpressRoute Global Reach Quiz5q
- ExpressRoute FastPath
- ExpressRoute FastPath Quiz5q
- ExpressRoute High Availability
- ExpressRoute High Availability Quiz5q
- Azure Load Balancer Overview
- Azure Load Balancer Overview Quiz5q
- Internal Load Balancer Configuration
- Internal Load Balancer Configuration Quiz5q
- Public Load Balancer Configuration
- Public Load Balancer Configuration Quiz5q
- Load Balancer Health Probes
- Load Balancer Health Probes Quiz5q
- Cross-Region Load Balancer
- Cross-Region Load Balancer Quiz5q
- Application Gateway Overview
- Application Gateway Overview Quiz5q
- Application Gateway Components
- Application Gateway Components Quiz5q
- URL Path-Based Routing
- URL Path-Based Routing Quiz5q
- Multi-Site Hosting
- Multi-Site Hosting Quiz5q
- SSL Termination and End-to-End SSL
- SSL Termination and End-to-End SSL Quiz5q
- Web Application Firewall Integration
- Web Application Firewall Integration Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons