Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Virtualization / Hyper-V / Hyper-V: Enabling Routing Between Internal Networks (Subnets)

August 2, 2021

Hyper-V: Enabling Routing Between Internal Networks (Subnets)

My task is to create multiple internal IP subnets and configure routing between them on my standalone Hyper-V stand. By default, Hyper-V doesn’t route traffic between networks on virtual switches. So to solve a task like this, you need to create a virtual machine with two network interfaces on different Hyper-V switches (in different networks) and configure routing between the interfaces using guest OS software (it may be either a VM running Windows Server with the RRAS role or a Linux host with a specific routing table). This method is not very convenient, because you have to run a separate VM for routing purposes only, and when adding a new IP subnet, you will have to reconfigure the routing table on your additional VM. However, I managed to figure out how to configure a Hyper-V host so that it could work as a router between different virtual switches/networks/IP subnets.

So, I have 2 virtual machines created in different internal networks on a Hyper-V host with the following IP addresses:

  • mun-dc01: 192.168.13.11/24 (gateway 192.168.13.1)
  • hh-dc02: 192.168.113.11/24 (gateway 192.168.113.1)

To allow routing on Windows Server, you must enable a special registry parameter — IPEnableRouter (it was discussed in the article on how to configure port forwarding in Windows).

Open PowerShell as an administrator on the Hyper-V host, edit the registry, and restart your host:

Set-ItemProperty -Path HKLM:\system\CurrentControlSet\services\Tcpip\Parameters -Name IpEnableRouter -Value 1
Restart-computer

IpEnableRouter - enable packet forwarding on Windows via registry

In the next step, create two new Hyper-V internal virtual switches. You can create them either in Hyper-V Manager or with PowerShell:

New-VMSwitch -Name vSwitchIntMUN -SwitchType Internal
New-VMSwitch -Name vSwitchIntHH -SwitchType Internal

hyper-v: create two internal network switches

Learn more about how to configure Hyper-V from PowerShell.

Then open Control Panel -> Network and Internet -> Network Connections on the Hyper-V host. You will see a list of network adapters on your host. There are two new virtual adapters (Hyper-V Virtual Ethernet Adapter) for the virtual switches you have created. Assign IP addresses to them using PowerShell or via the network adapter properties.
New-NetIPAddress -InterfaceAlias 'vEthernet (vSwitchIntMUN)' -IPAddress 192.168.13.1 -PrefixLength 24
New-NetIPAddress -InterfaceAlias 'vEthernet (vSwitchIntHH)' -IPAddress 192.168.113.1 -PrefixLength 24

As you can see, we have assigned the IP addresses of the default gateways on each subnet to these interfaces.

configure ip address for hyper-v switches

Connect each VM to its virtual switch (if you have not done it yet):

Connect-VMNetworkAdapter -VMName mun-dc01 -SwitchName vSwitchIntMUN
Connect-VMNetworkAdapter -VMName hh-dc03 -SwitchName vSwitchIntHH

Then your VMs will send traffic via these interfaces of virtual switches.

Make sure that Hyper-V virtual machines from different internal networks see each other. Check the routing using tracert and the port availability using the Test-NetConnection PowerShell cmdlet:

Test-NetConnection 192.168.13.11 -port 445
tracert 192.168.13.11

check routing between hyper-v internal networks

As you can see, the hosts are now responsible for ICMP ping and TCP. Note that Windows Defender Firewall settings in your VMs may block the traffic. Make sure you have allowed ICMP traffic in Windows Firewall and added other allowing firewall rules.

So, we have configured routing between multiple virtual networks on a Hyper-V host. The method is applicable for Hyper-V on Windows 10 and Windows Server 2016/2019.

3 comments
3
Facebook Twitter Google + Pinterest
Hyper-VPowerShellVirtualizationWindows 10Windows Server 2016
previous post
How to Download Offline Installer (APPX/MSIX) for Microsoft Store App
next post
How to Change Time Zone on Windows Server

Related Reading

USB Device Passthrough (Redirect) to Hyper-V Virtual Machine

March 15, 2024

Poor Network Performance on Hyper-V VMs in Windows...

February 20, 2023

Windows Cannot Find the Microsoft Software License Terms

April 19, 2023

Configure SR-IOV for Hyper-V Virtual Machines on Windows...

March 29, 2022

Import, Export and Clone Virtual Machines in Hyper-V

January 19, 2022

How to Install Windows 11 on a Hyper-V...

June 8, 2023

Managing Hyper-V Virtual Machines with PowerShell

June 8, 2023

How to Extend or Shrink Virtual Hard Disks...

January 19, 2022

3 comments

Travis Loyd August 29, 2021 - 11:02 pm

I’m looking for something which doesn’t appear to be on the net, maybe you could be the one to post the solution?
I setup a virtual-switch in hyperv:
New-VMSwitch -SwitchName “k-dmz” -SwitchType Internal
New-NetIPAddress -IPAddress 192.168.140.1 -PrefixLength 24 -InterfaceAlias “vEthernet (k-dmz)”
New-NetNAT -Name “k-dmz” -InternalIPInterfaceAddressPrefix 192.168.140.0/24

I can access VMs on this ip from the host system running hyper-v but cannot access the VMs from any other system on the local lan. I’ve tried adding routes to systems on the local lan, as well as setting up a route on the default gateway (router) of the local lan, and though it appears correct … tracepath reaches the hyper-v system and then reaches the vm, I cannot connect to the VMs from other systems on the local lan.

I’ve set the ‘IpEnabledRouter’ value in the registry, enabled the ‘Routing and Remote Access’, even installed ‘Remote Access’ feature, and then configured it by ‘Enable LAN Routing’. Still, no go. Not sure what else to try.

Reply
ekkowekko January 26, 2023 - 3:10 pm

I have the samen no connection to the other subnet

Reply
Christian November 8, 2024 - 12:16 pm

Thank you, you have made what I wanted to achieve so very simple.

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • How to Install and Configure Free Hyper-V Server 2019/2016
  • Poor Network Performance on Hyper-V VMs in Windows Server 2019
  • How to Install Windows 11 on a Hyper-V Virtual Machine
  • Windows Cannot Find the Microsoft Software License Terms
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine
  • Selecting the Number of vCPUs and Cores for a Virtual Machine
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top