Connect to nested Hyper-V VMs in Azure from another Virtual Network using VPN Gateway

Nested Hyper-V VMs in Azure has been available for a while now, its great for alot of different scenarios such as unsupported operating systems that run legacy applications to sandbox environments.

After creation of these VMs in a nested Hyper-V Virtual Machine (VM) you will possibly want to connect these VMs to other VMs in Azure. With the current restrictions on the Azure backend network it is not currently possible to create an external switch and give the Hyper-V VMs direct access to the Hyper-V hosts physical network.

Although with the mentioned restriction; there is a solution!

The solution is to configure NAT so that VMs can access the internet from the Hyper-V hosts public IP address and configure additional routing to enable connectivity to other VMs in Azure and vis-versa so other VMs in Azure can access the Hyper-V VMs

There is various blogs out there to allow you to create the initial setup of this; I will show quickly how to create a base setup, this blog post is to document how you can “Connect to nested Hyper-V VMs in Azure from another Virtual Network using VPN Gateway

Recommended blog post to assist you with configuring the initial setup:-

Azure Hyper-V host and Virtual network setup

Virtual Network:-

Virtual Network Name:- tamops-hyperv-vnet
Address Space:-
Subnet1:- NAT
Subnet2:- LAN
Subnet3:- GatewaySubnet10.2.4.0/24

Hyper-V Host:-

Virtual Machine Name:- tamops-hypervvm
Virtual Machine Size:- D2s_v3 (Dv3 & Ev3 are supported for nested virtualisation)
Nic1:- Subnet NAT –
Nic2:- Subnet LAN – IP forwarding enabled

Azure VPN Gateway also deployed in GatewaySubnet

Azure VM in different Virtual network setup

Virtual Network:-

Virtual Network Name:- tamops-production
Address Space:-
Subnet1:- vmtest
Subnet2:- GatewaySubnet

Virtual Machine Name:- tamops-vm1
Virtual Machine Size:- DS1_v2
Nic1:- Subnet vmtest –

Azure VPN Gateway also deployed in GatewaySubnet

Azure Hyper-V host setup

Server Roles that will be installed on the host:-

  • Hyper-V
  • Routing/RRAS
  • DHCP

DHCP will be used to automatically assign the hyper-V VMs IP addresses with RRAS used to route the traffic correctly.

PowerShell to install services:-

Install-WindowsFeature -Name Hyper-V,Routing,DHCP -IncludeManagementTools -Restart

Virtual Switch Setup

Create a virtual switch that will be used by Hyper-V VMs as a bridge for both NAT and routing

New-VMSwitch -Name "tamopsSwitch" -SwitchType Internal
New-NetIPAddress –IPAddress -PrefixLength 24 -InterfaceAlias "vEthernet (tamopsSwitch)"

DHCP Setup

A DHCP scope that will be used to assign IP addresses to the Hyper-V VMs, use a public and valid DNS server, for this I have used Google’s

Add-DhcpServerV4Scope -Name "tamopsSwitch" -StartRange -EndRange -SubnetMask
Set-DhcpServerV4OptionValue -DnsServer -Router

RRAS and Routing Setup

Open Routing and Remote Access

Right click on your VM name and select Configure and Enable Routing and Remote Access

Select Custom Configuration

Select NAT & LAN Routing

Click finish & Start service

Create NAT for internet access on Hyper-V VMs

Select IPv4 -> NAT -> Right click and new interface

Ethernet will be your interface you want to NAT
Ethernet2 is the “lan” subnet

Select as below

Static Routes Setup

Now to create 2 static Routes for the NICs

  • One for primary interface to avoid asymmetric routing
  • One to allow Azure VMs to communicate with Hyper-V VMs

On Static Routes -> right click and New Static Route, create these two as below

Image error, the second destination is:

The deployment so far

Hyper-V host is now setup and Hyper-V VMs will now be to communicate to the internet and also to other Azure VMs

At the start of this blog, I mentioned that I was going to show how Hyper-V VMs can communicate to another Azure VM in a different subnet with Azure Gateway VPNs in place.

Azure RouteTables need to be configured along with an additional Static Route configured on Azure Hyper-V host

Additional Routing Setup

Add additional static route as below

Create two Azure Route tables

Routetable Name:- Routetable1
Virtual network gateway route propagation enabled
Route:- RouteName: hyper-vvm AddressPrefix: NextHop: Virtual applicance with IP:

Assign to both LAN & GatewaySubnets of Virtual Network tamops-hyperv-vnet

Routetable Name:- Routetable2
Virtual network gateway route propagation enabled
Route:- RouteName: hyper-vvm AddressPrefix: NextHop: Virtual network gateway

Assign to vmtest subnet of Virtual Network tamops-production

Ready to test

For this test setup, I have configured an open Network security group (*) and also disabled Windows Firewall

Test ping from a Hyper-V VM to tamops-vm1 (Hyper-V VM has been assigned tamopsSwitch that was created earlier in blog post)

Test ping from tamops-vm1 to a Hyper-V VM

Awesome, the setup is now complete with the ability to communicate between Azure VM in a different Virtual Network to your nested Azure Hyper-V VM!


  1. Thank you for the quick guide, is it possible to also get direct connectivity between the hyperV VMs (the nested VMs) and the branch/remote office VMs connected via azure VPN gateway without having to create NATing on the azure vm/hyperV host? Or is this only possible from azure vnets?

    1. Hi Marco, for access from on prem to azure hyperV VMs, it’s the route table you pay attention too and the routing section of this blog.

      I used Nat for outbound Internet access.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s