Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

August 2, 2021 Hyper-VPowerShellVirtualizationWindows 10Windows Server 2016

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.

2 comments
2
Facebook Twitter Google + Pinterest
previous post
How to Download APPX File from Microsoft Store for Offline Installation?
next post
Changing Time Zone Settings in Windows via CMD, PowerShell, and GPO

Related Reading

Configure User’s Folder Redirection with Group Policy

February 3, 2023

Disable Built-in PDF Viewer in Microsoft Edge

February 3, 2023

Join a Windows Computer to an Active Directory...

February 2, 2023

Using Previous Command History in PowerShell Console

January 31, 2023

How to Install the PowerShell Active Directory Module...

January 31, 2023

2 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

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Configure User’s Folder Redirection with Group Policy

    February 3, 2023
  • Using Previous Command History in PowerShell Console

    January 31, 2023
  • How to Install the PowerShell Active Directory Module and Manage AD?

    January 31, 2023
  • Finding Duplicate E-mail (SMTP) Addresses in Exchange

    January 27, 2023
  • How to Delete Old User Profiles in Windows?

    January 25, 2023
  • How to Install Free VMware Hypervisor (ESXi)?

    January 24, 2023
  • How to Enable TLS 1.2 on Windows?

    January 18, 2023
  • Allow or Prevent Non-Admin Users from Reboot/Shutdown Windows

    January 17, 2023
  • Fix: Can’t Extend Volume in Windows

    January 12, 2023
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11

    January 11, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • How to Install Windows 11 on a Hyper-V Virtual Machine?
  • How to Install and Configure Free Hyper-V Server 2019/2016?
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine
  • Poor Network Performance on Hyper-V VMs in Windows Server 2019
  • How to Install VMWare ESXi in a Hyper-V Virtual Machine?
  • Hyper-V Boot Error: The Image’s Hash and Certificate Are not Allowed
Footer Logo

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


Back To Top