The scenario: I settle down for a bit of coding. I boot my PC, then boot up the various virtual machines I’ll be requiring. The issue is that each virtual machine ends up with a random IP address.
It’s not totally random since my DHCP will provide addresses in a limited range but I’d really like to start up for example my graph server and know its going to be at 192.168.1.27 and is called “neo4j”. Normally a DHCP server recognizes a machine requesting an address by virtue of its MAC address (all that 00:0c:29:59:17:93 type stuff). It recognizes the MAC, and hence hands out the same name and IP as it has before and will do in the future, i.e. 192.168.1.27 But a virtual machine is a ‘fake’ machine and will give itself a random generated MAC address which can vary if for instance you move the VM files somewhere else on your disk [*] or just rename the directory its in. A changed MAC means the DHCP server doesn’t provide the IP I’m expecting.
The solution is either to setup the VM to have a static IP address, but that sucks. There is a reason we have DHCP. Or we ensure the random generated MAC address is in-fact fixed. This can be done by a text editor on the .vmx file (I’m using VMware here) Changing the MAC address of a hosted virtual machine provides the details:-
Remove the three lines from the configuration file that begin with: ethernetN.generatedAddress ethernetN.addressType ethernetN.generatedAddressOffset
Add a new static MAC address line to the configuration file with help of the following entries: ethernetN.address = "00:50:56:XX:YY:ZZ" ethernetN.addressType = “static”
Although it is prescriptive about the MAC address it didn’t seem to be problem for me with VMWare Player 12. I just let the machine boot, noted its MAC then stopped the machine and edited the VMX to fix it to that MAC. So now I’m happy to boot my VMs in any way or order I like and know that http://neo4j:7474/browser/ will always correctly get to the right virtual machine.
[*] which is after all another advantage of VMs - I can store pre-configured machine setups on the NAS and bring them onto my desktop to actually run. And I might just rename as I move things around on disk.