Setting up file sharing between guest and host OS in Hyper-V using an Internal network
This post talks about making the network configuration settings made on a Hyper-V virtual machine in order to allow file sharing between the virtual machine and host OS. There are 3 types of Hyper-V networks that the virtual machine could be using – Private, Internal and External. Private does not allow any communication except between virtual machines using the same Hyper-V virtual switch. So in order to enable file sharing either an "Internal" or an "External" virtual switch is required.
To learn how to set up an Internal or External virtual switch and the nuances of each, refer here. This post assumes that the VM in question has been configured to use an "Internal" connection type.
On the VM, chose "Network and Sharing Center" > "Change Adapter Settings" to show that we have simple virtual adapter with no connection to any physical network.
Doing an ipconfig on the machine through command prompt shows the adapter is assigned a 169.254.X.X IP which shows it is a limited connection right now. This is because we are using an "Internal" virtual switch type on Hyper-V and are not connected through the physical adapter on the host machine.
So in order to get this virtual machine to be able to communicate with the host, I went about assigning it a static IP address. First, bring up the properties of the adapter from the right click menu.
From the "Ethernet Properties" dialog, selected the "Internet Protocol Version 4 (TCP/IPv4)" option and clicked on the "Properties" button.
When on the IPv4 properties dialog, I need to set a static IP on the adapter that is on the same subnet as the host machine. What this will enable is the ability for the Virtual Switch to route communication between the host and guest operating systems. I chose the IP address shown below because my host machine runs with a 192.168.1.X IP. Set the subnet mask to 255.255.255.0 as shown to ensure same subnet and clicked "OK" to finish.
Now I could have made other settings such as the gateway (which shouldn’t have mattered since there is no physical network connection and Preferred DNS Server which I will eventually have to come back to when I set up the DNS service on this machine. But I am doing the bare minimum here to get the communication working.
On the "Ethernet Properties" dialog, clicked "Close" to apply the settings and move along.
Confirmed that the settings were applied.
Created a new folder called "Transfer" to serve as a go-between for file transfers between the guest and host OS and selected to share it with "Specific people…"
Clicked on "Share" to begin sharing the folder.
The "Network discovery and file sharing" dialog shows up. Selected "No, make the network that I am connected to a private network". It wouldn’t matter greatly because the machine is on an internal network anyway but it is the right choice to make.
Once that is done, the shared folder should be accessible at the path indicated in the screen below. Clicked on "Done" to close out of this.
So let’s try accessing this folder from the host. Opened a file explorer window and type the path shown above in the address bar. The first time connection will require username and password to be typed in. We get away with not using domain specification here because the virtual machine has not been added to a domain yet. If we did, we may have had to use a valid domain user login.
In any case, once authentication is through you are able to view the contents of the folder on the host operating system. Added a file here to complete the test.
And here’s the file on the guest. Besides testing the ability to transfer data, this has also verified the working of the virtual switch.
And that’s all there is to that.