User Defined Routes (UDR)

User Defined Routes (UDR) allow you to control the routing of network traffic within your Azure Virtual Network (VNet) and to or from your VNet. By default, Azure provides system routes that handle basic connectivity. UDRs override these system routes when specific routing conditions are met.

Note: UDRs are configured on a subnet basis. When a route is applied to a subnet, all virtual machines within that subnet will use the defined routes.

Why Use UDRs?

UDRs are essential for scenarios such as:

Key Concepts

Route Table

A route table is a collection of routes that you create. A route table is associated with a subnet. Each subnet can be associated with at most one route table. A route table can be associated with multiple subnets.

Routes

Each route in a route table consists of the following components:

Route Table Configuration

You can create and manage route tables and their associated routes using the Azure portal, Azure PowerShell, Azure CLI, or ARM templates.

Creating a Route Table (Azure Portal Example)

  1. Navigate to the Azure portal.
  2. Search for and select "Route tables".
  3. Click "+ Create".
  4. Fill in the required details: Subscription, Resource group, Region, Name, and Propagation of gateway routes.
  5. Click "Review + create" and then "Create".

Adding a Route

  1. Navigate to your created route table.
  2. Under "Settings", click "Routes".
  3. Click "+ Add".
  4. Enter a "Route name", "Address prefix", "Next hop type", and if applicable, "Next hop address".
  5. Click "Add".
Tip: When specifying the "Next hop IP address" for VirtualAppliance, ensure it's the private IP address of your NVA's interface within the VNet.

Associating a Route Table with a Subnet

  1. Navigate to the Virtual Network containing the subnet.
  2. Under "Settings", click "Subnets".
  3. Click on the subnet you want to configure.
  4. Under "Route table", select the route table you created.
  5. Click "Save".

Route Table Propagation

When you create a route table, you can choose whether to propagate routes from:

These propagated routes are automatically added to the route table. You can also add static routes manually.

Route Hierarchy and Order of Operations

Azure follows a specific order when determining how to route traffic:

  1. User Defined Routes (UDRs) in the route table associated with the subnet.
  2. System Routes applied to the VNet.
  3. Virtual Network Gateway Routes (if applicable and propagated).

If multiple routes match a destination IP address, the route with the most specific prefix (longest prefix match) is chosen.

Warning: Be cautious when configuring UDRs, especially those that route traffic to None or an incorrect NVA IP. Misconfiguration can lead to network connectivity loss.

Example Scenario: Forcing Internet Traffic Through an NVA Firewall

To force all internet-bound traffic from a subnet through an NVA firewall, you would:

  1. Deploy an NVA firewall in your VNet.
  2. Create a route table.
  3. Add a route to the route table with an "Address prefix" of 0.0.0.0/0 (representing all internet traffic).
  4. Set the "Next hop type" to VirtualAppliance and the "Next hop IP address" to the private IP address of your NVA firewall.
  5. Associate this route table with the subnet(s) whose traffic you want to direct through the firewall.
UDR flow through NVA
Diagram illustrating traffic flow through an NVA using UDRs.
Azure CLI Example: Creating a UDR route
az network route-table route create \ --resource-group MyResourceGroup \ --route-table-name MyRouteTable \ --name RouteToNVA \ --address-prefix 0.0.0.0/0 \ --next-hop-type VirtualAppliance \ --next-hop-ip-address 10.0.1.4
Azure CLI Example: Associating Route Table with Subnet
az network vnet subnet update \ --resource-group MyResourceGroup \ --vnet-name MyVNet \ --name MySubnet \ --route-table MyRouteTable
Important: Ensure your NVA firewall is properly configured to allow and forward traffic as intended. The NVA must have its own routes or be able to handle the traffic directed to it.

Troubleshooting UDRs

If you encounter connectivity issues:

User Defined Routes are a powerful tool for customizing network traffic flow in Azure. By understanding their configuration and behavior, you can implement robust and secure network architectures.

Further Reading