How to Setup Hyper-V Networking on Windows 8


[Update 7. oct. 2013: Check out the follow up post here – it shows a better way]

It seems that the best way to setup networking in Hyper-V on a Windows 8 machine is quite far from obvious. I have spent some time getting this working as it should, so read on…

The Goal

Is quite simply that I want my VMs to just work seamless with my Host machine and whatever network connection I’m using and – in my case – a guest AD.

This used to be really simple with VMWare Workstation but after converting my machines to Hyper-V there is a catch or two.

Note that this applies to a mobile working scenario where I run everything on a laptop and it frequently changes whether I’m using a wired, wifi or mobile net.

The Environment

I do SharePoint development and this post is written in that context, however it should all be generally applicable to Hyper-V.

My local Hyper-V (SharePoint Dev) environment consists of two guests:

  • An AD server that should not communicate outside my box
  • A SharePoint server that need to communicate with my host, the guest AD and generally networking

In addition I need to connect with Remote Desktop to the guest machines with the host (the Hyper-V console is useless for all but boot and network configurations).

The Hyper-V Network Settings

The steps to configure the network on the host are:

  1. Create an external virtual switch for each of your external network adapters in the Hyper-V manager
  2. Create an internal switch for the connection between host and virtual machines (and in my environment between the AD and SharePoint server)
  3. A catch: In my case the mobile adapter was not selectable (not sure if that is always the case) when I create a virtual switch.

    In that case create an internal switch (name it “External” something as it will be configured for that)

    1. Go to your Network Connections, choose your mobile adapter, Sharing and choose to share the connection with the newly created virtual switch (see the picture below)

  4. Name them all appropriately otherwise you’ll regularly end up being confused 😉

    After that your Hyper-V settings look something like this:

  5. Finally you need to pick some static IP addresses for your internal network as you’ll want the host to communicate with the guests and the guests to be able to talk to each other. There is no DHCP on the internal switch (would be a reasonable feature request for the next version of Hyper-V). I this case I picked 192.168.10.2 for my host:

  6. If you want to be able to refer to your guest machines by their names you need to add a couple of entries to your hosts host file 😉 Edit the file C:\Windows\System32\Drivers\etc\hosts and add a line for each guest

    I picked 192.168.10.10 for my AD guest and 192.168.10.20 for my SharePoint guest:

The Guest Configuration

First of all you need to connect the virtual switches appropriately to your guests in the Hyper-V Manager:

  • For the guests that only need to communicate internally connect only the internal switch
  • For the guests that need full internet access connect all the switches

Finally we need to configure the guests themselves. Connect to each one using the Hyper-V console:

  1. For the AD guest server (internal communication only) assign the ip address 192.168.10.10 (the one picked above) – there should only by one network adapter
    1. When you change the IP address for an AD server you also need to change the address appropriately in the DNS manager. Simply start the DNS manager and click through the nodes and change all IP addresses to the new address
    2. If you have a registration for other clients (other guest machines) update those records to the IP you chose for them
    3. Reboot the guest
  2. For the guests that need network access
    1. Assign the chosen IP to the internal network, in my case, 192.168.10.20
    2. Add two lines to the guest machines host file to make sure that the AD guest server can be found:

      “192.168.10.10 ad01” and “192.168.10.10 ad01.domain.local” where the second is the FQDN of the AD server

    3. You should now have a number of network adapters that are connected to the host’s physical adapters and it will automatically figure out which ones are connected and use whichever is appropriate. I recommend that you named them appropriately in the guest.
    4. Catch (do not skip this): I did however find that it was unable to correctly figure out whether the mobile adapter was connected or not (likely because I created it as an internal switch). I fixed that by prioritizing the mobile network connection last so it will only use the mobile if all others fail. You just need to set the “network metric” to something high (high is lowest priority), follow the process in the picture below

That’s it for the guests!

RDP Access

Finally you’ll want to access the guests through RDP so stuff like copy/paste and fullscreen works. You can of course use whatever RDP manager you prefer, here I’ve just used the standard one.

Make a connection for each Guest access and save it somewhere (Desktop?).

Run the command “mstsc” and setup the options you like and save the Connection. In particular enable “Clipboard” and “Drives” in the “Local Resources” tab. That will enable you to copy/paste both text and files between the guest and host. Will also grant access to the host’s drives.

In my case:

Going for the Advanced Mode?

While the settings above work fine; there is always room for improvement.

I think it would be better to install a third machine as a firewall/router so the firewall handled all external connections and boxed in the essentially rogue guest machines. They really only need to communicate externally on port 80/443.

I will give m0n0all a go soon 🙂

Troubleshooting

Once in a while something goes wrong. Sadly.

My normal way to troubleshoot is simple to do a “tracert http://www.google.dk” and to notice what network adapter is being used for the communication.

Sometimes it picks the wrong nic (one without Internet access) for whatever reason (you did remember to set the metric above, right? This is what it does). “Ipconfig /flushdns” sometime solves the problem otherwise disable the offending nic in the guest (temporarily).