How to User-Defined Routing with Azure Resource Manager

As I was testing with a Virtual Appliance that handles the traffic in my Azure VNET, I needed to create some User-Defined Routing. My deployment is done in Azure Resource Manager, so I was searching for a way to set User-Defined Routing with Azure Resource Manager and PowerShell. Most of the scripts I found where based on Azure Service Manager.

So I would like to share the Powershell (1.0) script with you.



$VMname = [name of your Virtual Appliance]
$ResourceGroup = [ResourceGroup]
$Location = [Location]
$NameRouteTable = [NameRoutingTable]
$NameRoute = [NameRoute]
$NextHopIP = [IP of your Virtual Appliance]
$VNET = [Your VNET]
$VNETid = Get-AzureRmVirtualNetwork -Name $VNET -ResourceGroupName $ResourceGroup
$Subnet = [Your Subnet]
$SubnetAddressPrefix = [Your Subnet Prefix]
$routeTable = Get-AzureRmRouteTable -ResourceGroupName $ResourceGroup -Name $NameRouteTable

$nicConfig = Get-AzureRmNetworkInterface -ResourceGroupName $ResourceGroup -Name $VMname
$nicConfig.EnableIPForwarding = $true
$nicConfig | Set-AzureRmNetworkInterface

New-AzureRmRouteTable -Name $NameRoutingTable -ResourceGroupName $ResourceGroup -Location $Location
New-AzureRmRouteConfig -Name $NameRoute -AddressPrefix -NextHopType VirtualAppliance -NextHopIpAddress $NextHopIP

Get-AzureRmRouteTable -ResourceGroupName $ResourceGroup -Name $NameRouteTable | $routeTable = Add-AzureRmRouteConfig -Name $NameRoute -AddressPrefix -NextHopType VirtualAppliance -NextHopIpAddress $NextHopIP | Set-AzureRmRouteTable
#Verify if everything is set correctly
Get-AzureRmRouteTable -ResourceGroupName $ResourceGroup -Name $NameRouteTable

Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $VNETid -Name $Subnet| Set-AzureRmVirtualNetworkSubnetConfig -AddressPrefix $SubnetAddressPrefix -Name $Subnet -VirtualNetwork $vnet -RouteTable $routeTable

Usuer Defined Routing in Azure

About Daniel Etten

I currently work as a Premier Field Engineer (PFE) at Microsoft. Together with Paul, a former colleague of mine at KPN, I started this blog to share our experiences with Azure to other Azure minded people and as a personal repo of Azure info.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Leave a Reply

Your email address will not be published. Required fields are marked *