Routing Traffic between Subnets in your Hyper-V Lab

Sometimes I need to replicate customer issues in a Hyper-V lab to fully understand and fix the problem. My labs are typically pretty small and disposable - I set them up for a specific purpose and then trash them. For this reason I use Windows 8 Hyper-V running locally on my laptop. This was working great for me until recently when I needed to replicate a customer problem involving a specific site/subnet configuration. I wanted a way to route between subnets within my Hyper-V lab.

This is a quick and painless guide to quickly set yourself up a software-based router (Windows 2008R2 Routing and Remote Access) to route traffic between subnets in your Hyper-V lab. There may be other methods out there but this works for me.

1.      Set up your lab as normal. I’m going to use the diagram below for my example. The goal is to route traffic from Network A to Network B and back the other way.

 

 

2.      Create a new VM in Hyper-V. Name it something obvious like “Router”. Allocate at least 512MB RAM and 10GB Storage.

3.      Give it a second Network Adapter. In the settings for the “Router” VM, click “Add hardware-> Network Adapter->Add”.

Ensure both of your network adapters are connected to the same Hyper-V Network. In my diagram below, you’ll see I’m using a virtual network called “Private Switch”.

 

4.      Install Windows Server 2008 R2 on the “Router” VM.

5.      In Server manager, Install the “Network Policy and Access Services” Role, Followed by “Routing and Remote Access Services”

 

6.      Configure your two Network Interfaces on the “Router” VM.

Network A (NIC1)

Network B (NIC2)

IP Address: 192.168.0.1

Subnet Mask: 255.255.255.0

Default Gateway: blank

DNS Server: blank

IP Address: 192.168.1.1

Subnet Mask: 255.255.255.0

Default Gateway: blank

DNS Server: blank

7.      In Server Manager, Right click “Routing and Remote Access” and select “Configure and Enable Routing and Remote Access”

8.      Select “Secure connection between two private networks”. Select “No” then “finish”

 

 

9.      Your Windows router is now set up!

 Now you just have to set the default gateway for the rest of the machines in your lab (by using DHCP options or static configuration).

Network A – Default gateway of 192.168.0.1

Network B – Default gateway of 192.168.1.1

 

Clients in Network A can now be routed to Network B and vice-versa. Use Ping to test it works.

Comments

  • Anonymous
    April 23, 2013
    I run a RouterOS instance for this with hardly any storage/memory, it has features like iBGP and OSPF which make it very useful and you can't get with RRAS unfortunately.  You can also control routing between various VLAN's when supplied with a single tagged interface and it has a nice windows UI you can run without needing to remote desktop.There are other solutions out there that also have decent features, but I haven't managed to get by with RRAS for this purpose.  It's good for client access but there's some weird behaviour and not enough control or protocols supported at all.  Plus some odd packet loss sometimes with traceroutes going through it.
  • Anonymous
    April 25, 2013
    Another method which does not need an additional VM serving as a router is by simply changing the following registry key on your localhost: HKLMSystemCurrentControlSetServicesTcpipParameters - IPEnableRouter to 1.
  • Anonymous
    June 20, 2013
    Thanks for the wonderful information. Let me tell what i tried!I want to have Networks.Network A : 10.0.0.0/8Network B: 192.168.1.0/24I created a new windows 2008 R2 machine as router. I installed routing and remote access as mentioned above. I added two network adaptors in this machine.10.0.0.200192.168.1.200I have a domain controller in Network A (IP : 10.0.0.1); hence i assigned 10.0.0.200 as default gatewaye to it.I added another stand alone machine in network B (IP: 192.168.1.1) with default gateway as 192.168.1.200.All the network adaptors on the same Hyper Networkfrom router, I am trying to ping as followingfrom 10.0.0.1 to 10.0.0.200>>>>>>>Successfrom 10.0.0.1 to 192.168.1.200>>>>>>Request time outfrom 192.168.1.1 to 192.168.1.200>>>>>>Successform 192.168.1.1 to 10.0.0.200>>>>>failed.can anybody tell me if i have missed anything ??
    • Anonymous
      December 22, 2016
      Don't ping the router VM, ping the machines in both subnets to each other.
  • Anonymous
    July 09, 2013
    add a route between A and B and B and A