Had a short training on VMWare on Tuesday, the software development department finally got the official permission (read: get a license) to use VMWare Workstation. I’m no stranger to Virtual Machines (VMs) – started playing with Virtual PC 2005 a fwe years back and I understood the general concepts of hardware virtualization. The biggest problem I have with VMs in general is the slowness; I’d rather develop directly on my PC, which is faster. Can’t say I’ve delved deep into it, but I know enough to utilize it and be dangerous .
Regardless, virtual machines provide a way to simulate multiple computers and I’ve done 3-tier software testing (client to app server using WCF and app server to SQL 2005 backend) to verify our framework can support both 2-tier (client –> DB) and 3-tier deployments. Rarely used it for development, again due to speed.
Fast forward to the current time, I’d like to be able to do some coding on Windows 7; unfortunately Windows 7 is not quite sanctioned yet to be deployed, and it’s a pain to have to dual-boot. I do have Windows 7 at home, but got way too many experimental stuff on it . So, I’m setting up a Windows 7 VM so I can do some coding on it.
Now, nothing wrong with running the VM within VMWare, but I always find that it is a bit sluggish unless I go to full screen mode. If I do so, it’s a bit of a pain to go back and forth between the host and the VM, and it also means that I have to do it at the host. Ideally, I’d like to remote desktop into it (for whatever reason, I also feel remoting into a VM session makes for a snappier UI response).
However, this is not immediately possible to do without some setup; out of the box VMWare provides VNC connectivity, so you can use that but I am spoiled by remote desktop – it is just way nicer than VNC. Of course one of the advantages of VNC is that if someone connects to it, the original don’t lose the view of the PC, so different tools for a different job.
In any case, I’d like to be able to remote desktop into my VMs – there are 2 ways to set this up, one is faster but it is considered as ‘nice’ and may cause problems with typical corporate network setups. Let’s look at the first approach:
The first approach is to set up the VM setting to have it’s network adapter be a Bridged connection. This basically sets the VM to use the host’s network card as if it were its own network card. This also means that the VM will get an IP based on the host network’s settings (usually DHCP-based). Essentially it brings the network connectivity of the VM to be at the same level as the host. Now, in a corporate environment (usually domain-based), this may not be allowed, or you may have trouble with accessing the network at all if your VM is not added to the domain. On a local (home) network, it also means it can communicate with other computers on the same network (good), but if it gets infected with a worm / virus it can also spread to the other computers (bad).
Depending on your environment, bridging may be fine and if you can do that then by setting it to Bridged mode you can then remote desktop to the VM (you have to remember to turn it on within the VM).
However, in my current situation, setting a VM network in bridged mode is not condoned and we have to set it to NAT setup. Each VM that you spun will then get a typical internal IP address (192.168.XXX.XXX); but that means you cannot get to it from the outside. So what to do? The answer was provided in this post by rsa911– I’m just providing the nice UI snapshots (and also as a reminder for me on how I got it to work in the future).
In NAT mode, each VM is given an internal IP address and VMWare essentially becomes the bridge between the host and the VMs that runs in it. Fortunately, you can do port forwarding to these internal IP address. As detailed here, Remote Desktop uses port 3389 to listen to incoming RDP requests. So what we need to do is forward an unused port to each VM’s port 3389 and we should be able to remote into them. Let’s see how that’s done.
To do port forwarding, we need to access the Virtual Network Editor from VMWare Workstation (under the Edit Menu –> Virtual Network Editor). The dialog above should show up – select the network adapter that is set to NAT. Then click on the ‘NAT Settings…’ button, the following dialog will show up:
Click on the ‘Add’ button, and a dialog to map incoming port shows up; the dialog below is filled with the following information:
- Listen to port 9997
- Any TCP communication to that port, forward it to the VM with IP of 192.168.118.130 on port 3389 (default RDP port)
Tweak it to satisfy your setup – the host port just needs to be an unused port (in this example I use 9997), the VM port needs to be 3389 (unless you’ve changed it) and the VM IP address needs to be the IP address assigned to the VM you’re running (in Command Prompt run ipconfig to easily see this); this is what my output looks like:
When done, click OK and the NAT Settings dialog will show up your port forward:
So now I’ve set up VMWare so any incoming request to port 9997 will be forwarded to port 3389 on the VM that has IP of 192.168.118.130. Remember that for Remote Desktop to work, you still need to make sure your VM has RDP enabled and you have users with passwords added as Remote Users.
The question is then how do you issue the remote desktop request? Well, you use the host’s IP (or machine name) as the target, but you provide the port number as well:
The VMWare is hosted in my laptop (mbudimane6500) and I’m providing the port RDP should use (9997). Remember that in a domain environment it’ll try to login as a domain user (DOMAIN_NAME\username format), so if your VM machine is not part of a domain you have to change the username to use to log in.
If you’ve done everything as mentioned above, now you can remote desktop into your VM machines in a NAT environment . Remember also that you have to do the port forward for every VM that you wanted to remote into – each one will have a different IP address and each one will need to have a different port number. Hope this helps others.