Thursday, March 4, 2010

Windows Virtual PC: Network Between Host and VM Using Loopback Adapter

If you want to create a network between the host and VM using Windows Virtual PC in Windows 7 then this guide is for you.  This is especially useful if you need to communicate with the VM when not connected to a network.  WVPC offers a number of networking options:

  • None – no networking
  • Internal Network – Network between hosted VMs (but not the host)
  • NAT – Sets up a virtual NAT to allow the VM to access the internet
  • Bridge – Allows the VM to use one of the hosts network adapters to access the local network

I do all my work from my laptop, including hosting my VM so at home, when connected to my home network (LAN) i use the bridged mode – my laptop connects using the wireless adapter and the VM uses the Ethernet adapter.  This way i can see both the host (laptop) and VM on the network and they can talk to each other great.  The problem arises when i am travelling and not connected to a network – in this scenario bridged mode is no use because there is no network for the VM and laptop to communicate to each other.  What I want is a ‘host-only’ network mode, similar to what VMWare offers.  The following steps allow you to set up a local bridged network that allows the two to communicate on a private network:

Setup a loopback adapter on the Windows 7 host

  1. In the start menu type command, right-click Command Prompt and select Run As Administrator to open a command window with administrator privileges
  2. Type hdwwiz and press enter to start the Add Hardware Wizard
  3. Click Next
  4. Select Install the hardware that i manually select from a list (Advanced) and click Next
  5. Select Network Adapters from the list and click Next
  6. Select Microsoft in the Manufacturers list and then select Microsoft Loopback Adapter in the Network Adapter list and then click Next
  7. Click Next to install the loopback adapter

See here for the above instructions including images of each step.

Configure the loopback adapter

  1. Go to the Network & Sharing Centre (from the start menu)
  2. Click Change Adapter Settings from the list on the left
  3. Go to the properties of the Microsoft Loopback Adapter
  4. Disable all items, except Client For Microsoft Networks, Virtual PC Network Filter Driver and Internet Protocol Version 4 (TCP/IPv4).  If the Virtual PC Network Filter Driver is not enabled, the VM will not see the adapter
  5. Go to the properties of the IPv4 protocol and set the IP to a reserved private IP, such as 192.168.x.x or 10.x.x.x, that does not conflict with any other network you will connect to.  Ensure that the gateway is left BLANK otherwise it may cause issues with other networking
  6. Click OK until the dialogs are all closed
  7. Open regedit and browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
  8. Find the subkey (0001 … 00xx) that corresponds to the loopback adapter (DriverDesc = Microsoft Loopback Adapter)
  9. Add a DWORD called *NdisDeviceType (don’t forget the asterisk at the start) with a value of 1
  10. Go to the start menu and type View Network Connections to open the list of network adapters
  11. Disable then enable the Microsoft Loopback Adapter to apply the registry changes.  The loopback adapter will no longer appear in the Network and Sharing Centre but will operate as a network endpoint on a private network, which is exactly what we want.  See here for more information.

See here for a thread discussing the registry change

Configure the VM to use the loopback adapter

  1. Ensure the VM is shutdown (not hibernated) to simplify the following steps
  2. Right click the virtual machine .vhd file and select Settings
  3. Change the network adapter to use the new loopback adapter (if you cant see it in the list, check that the filter driver mentioned above is definitely enabled on the host)
  4. Save the settings and run ipconfig from the command-line to check the IP has been successfully set
  5. Start the VM

Configure the loopback adapter in the VM

  1. Go to the properties of the Local Area Network connection in the VM
  2. Go to the properties of the IPv4 protocol and use an IP on the same subnet as the host (eg if the host is 192.168.1.1, use 192.168.1.2 for the VM)
  3. Save the settings and run ipconfig from the command-line to check the IP has been successfully set

Note that pinging does not appear to work using this configuration, even when IP addresses are specified.  However i have been able to successfully perform all other network operations without problem.  The drawbacks with this approach are that the VM cannot communicate to the hosts network when it is connected.  In this scenario, either change the VM to bridge via a different, connected adapter on the host as outlined above, or setup a proxy on the host that can forward requests from the VM to the network.

6 comments:

Unknown said...

hi there i followed yr instructions and then tried watever u asked to but still its not workin..i m using virtual pc to test trixbox ...it is giving me a ethernet fail..so thts why i cannot connect to it as u need an ip to connect to it..so plzz help me...

Unknown said...

Hi, if you rightclick the virtual machine and choose settings you will be able to activate a second network adapter for the VM. (Note that the VM has to be shutdown, not hibernated, for the user to be allowed to do this.)

This way you'll be able to stay on the network and have network connection between Windows 7 and the VM:-)

venugopal said...

Very good site, brilliant write up. Windows Network Setup

Broom said...

Works great, coding PHP on windows 7 editor, on local debian server by VM. Great, tnx alot!

dsds said...

Great post. I think it is good for visitors. I like this kind of website where has a lot of real information, It proved to be very helpful. Thanks for admin, His creativity, Presentation, Information and all is good.
home network setup

Patrick Co Eban said...

Networking Projects for Final Year CSE Students


The IEEE Network projects Networking Projects for Final Year CSE Students has direct impact on undergraduate and graduate student education and training. Final Year Engineering Students who are software developers can structure a project around building a network firewall application Final Year Project Centers in Chennai

JavaScript Training in Chennai

JavaScript Training in Chennai