I recently had a requirement to build a non-persistent VMware View desktop pool that acted as if the linked-clone virtual desktops had static computer names with static IP addresses. The reason was that the vendor of a particular clinical application ties its licensing to both the computer name and its IP address. If they don’t match a predefined table, the client application won’t launch.
Try DHCP Reservations
By default, VMware View non-persistent (floating) desktop pools rely on DHCP. My first idea was to build a new DHCP scope for this desktop pool that made use of DHCP Reservations (DHCP reservations are permanent lease assignments that are used to ensure that a specified client on a subnet can always use the same IP address).
My problem was that DHCP Reservations work by configuring a specific IP address to a specific MAC address. Unfortunately, non-persistent desktops receive a new MAC address upon rebuild or recompose — which ruled out this option.
Try Scripting the Solution
After toying with the idea of using Group Policy Preferences with Item Level Targeting that references the NetBIOS Name, I decided it would be easier just to script the solution.
In VMware vCenter, I gave my parent virtual machine a second vNIC that I’ll use for the static IP and scripting solution. The first vNIC will remain DHCP.
When building a desktop pool in VMware View there is an option to run a Post-Synchronization Script. The solution I ended up going with was to create a script that will change the IP address of the virtual machine after it is built via the NETSH command. The script has to reside on your Parent Virtual Machine.
I created a .BAT file that looks something like this (each IF should begin a new line):
IF %computername%==VDI-GETRAIN-1 NETSH interface ip set address name="Local Area Connection" static 172.0.0.51 255.255.255.0 172.0.0.1 1 IF %computername%==VDI-GETRAIN-2 NETSH interface ip set address name="Local Area Connection" static 172.0.0.52 255.255.255.0 172.0.0.1 1 IF ... etc ...
Summary of Static IP Addresses in a VMware View linked clone pool
Here is what happens when VMware View builds a new desktop in this pool:
- VMware View names the desktop VDI-GETRAIN-1 to VDI-GETRAIN-20 as defined in VMware View
- Desktop receives a new virtual MAC address as normal
- Desktop receives a new IP address as determined by the DHCP server
- VMware View is done building the desktop and then runs the Post-Synchronization Script
- The Post-Synchronization Script changes the virtual machine’s IP address to a value that matches its computer name
- The computer name and IP address are now consistent and remain unchanged each time the desktop or pool is refreshed or recomposed
- Now that computer name and IP appear to be static, the vendor’s application meets the licensing requirements and launches properly
If you have also needed static IP addresses in a floating VMware View linked clone desktop pool but engineered a different solution, I’d like to know.
what if the pool contains 300 desktops? fun fun fun with that batch.
I’ve been following your blog, and I just want to thank you for sharing your experiences with rest of the world. look forward seeing more of challenges and resolutions!
Jason, thanks for this solution. I don’t have it working yet, but a few things did be come apparent: 1. The %computername% on a Windows machine will always be capitalized. So if you have created the script with lower case names, the script will run, but not change anything. You have it right in your script, but I didn’t – at first. 2. If your master image IP settings are set for DHCP, there is a good chance that your DNS settings are as well. I added two lines at the end of my script to add my DNS servers:
NETSH interface ip add dns “Local Area Connection” 10.0.0.24 NETSH interface ip add dns “Local Area Connection” 10.0.0.25 index=2
NET STOP VMWVvpsvc NET START VMWVvpsvc
Instead of creating manual entries for each computer name and maintaining them in an excel spreadsheet, why not put conditions in the script to parse the computername and pull the necessary values?
For example, all of our devices have a name similar to VTST55100, VTST55101, VTST55102, etc.
The following line will pull only the last three digits from the %computername% value: set computernumber=%computername:~-3%
Then use this variable to modify the IP address as follows: set ipaddress=172.22.100.%computernumber% netsh interface ip set address name=”Local Area Connection” static %ipaddress% %subnetmask% %defaultgateway%
Obviously this only works with a naming scheme that resembles the IP address. But if that’s your case (and if not there’s a good argument to make it this way) then this should make managing this script a non-issue.
I also included lines to configure our DNS (as the above post pointed out as well).
Hi Jason
Thanks for the DHCP reservation article , I am having a hard time getting the IF %computername%==copmuter001 to work. I am not really sure why it keeps coming back as “the sytax of the command is incorrect. I am saving the file as a batch file, does that have to anything to do how the IF %computername%== statement gets excuted? Please help thanks
Erick
Thank you everyone for your comments.
I’ve since determined it is both better and easier to provide this desktop pool two vNICs.
One for normal DHCP that remains unchanged. The second vNIC I target with my script to give it a static IP address that matches a pre-determined computer name.
My script looks like this:
I would like to change the properties of a cloned vm (IP, mask, etc). No vmwaretools installed in the host os. Can I do this using scripts (powerCLI or other).
Thx. Salil