How do I manage my HOSTS/LMHOSTS file and/or better manage a virtual machine IP that changes?
June 5, 2008 8:50 AM   Subscribe

How do I manage my HOSTS/LMHOSTS file and/or better manage a virtual machine IP that changes?

I'm on a Windows XP machine. I have a linux virtual machine (Centos 5) running in VMWare Workstation.

I'm doing some web development on this virtual machine and I use the hosts file to make some dummy entries like:

192.168.1.4 www.domainnamestaging.com
192.168.1.4 domainnamestaging.com
192.168.1.4 www.anothersiteimworkingon.com
192.168.1.4 anothersiteimworkingon.com

and in the lmhosts something like

192.168.1.4 linux

Then I'll make a SMB share to \\linux\whatever and I can test my website with http://www.domainnamestaging.com/ and that all works fine. The VMWare networking is set to Bridged networking which just treats the Virtual Machine as if it's on my router like any other machine.

The only problem with this is sometimes I'm working at a coffee shop with no connectivity in which case I have to change the Virtual Machine's networking to a "private network" where the IP changes to something like 192.168.199.128 and I have to go through the HOSTS and LMHOSTS file and change all those entries to the new IP address. Or the coffee shop will have internet access but their router gives me a completely different IP address for the Virtual Machine.

I'm thinking I could write a script to search and replace all the IP addresses in those two files, but I'm guessing there has to be a better way? Is there some program/networking trick that switches all this stuff easily, bonus points if I don't have to run anything, it just works regardless of how it's connected?
posted by bertrandom to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
I'm not at my desk now, but isn't there also an option to have it work in "NAT mode." I think that's what I use and the IP address of my Linux VM never changes.
posted by meta_eli at 9:15 AM on June 5, 2008


You can create a private virtual network with VMWare (with separate network interfaces in both the VM and the host OS). Assign static IP addresses to those addresses. Do not assign a default gateway (so both machines will continue to use your real network for internet access). Finally, set up your host entries to point to the private network IPs.

I'm pretty sure the VMware documentation will give more info. In fact, I'm pretty sure that there is a private network option when defining a new network interface (in VMWare fusion it is labeled "Host Only").
posted by Good Brain at 9:19 AM on June 5, 2008


Response by poster: When I have no connectivity, I used this "Host Only" feature you guys are referring to, but I do want my virtual machine to be on my main network still when I'm at home, for example, if I want to access shared network drives from my virtual machine. It's good to know that you can set it up such that it still has internet access though, I thought it was isolated when it was in that mode. Any other ideas?
posted by bertrandom at 9:51 AM on June 5, 2008


Response by poster: meta: How does the NAT mode work? It says, "Used to share the Host's IP address", how would I connect to that virtual server then from my host machine? Or are you referring to the "Host Only" mode that Good Brain talks about (and that I referred to as "private network" in my original question). Thanks!
posted by bertrandom at 9:54 AM on June 5, 2008


My experience is with VMWare Fusion on Mac, but I assume it is the same. NAT mode does just like it says on the tin; it's like NAT on your router.

For example, the PC gets assigned the address 192.168.1.100 from DHCP on the router.

But VMWare also assigns my PC another address on a different subnet (192.168.15.1 in this case), and it gives my Linux VM image an address on that subnet too (192.168.15.129).

So the Linux virtual box can still access the Internet outbound, and I can also always get to it from my desktop via the .15.129 address. Likewise, the image can ping my desktop at the .15.1 address.

Since VMWare is now assigning the addresses, they don't change and it doesn't matter whether you're actually connected to the 'net or not.

Make sense?
posted by meta_eli at 4:52 PM on June 5, 2008


Best answer: I could have been more clear. I was suggesting you create a separate virtual interface for the host-only/private network. Your host and virtual machine can be on both networks simutaneously.
posted by Good Brain at 6:43 PM on June 5, 2008


Response by poster: Thanks for your help guys, I just added a second Ethernet interface for a host-only and set it to static instead of DHCP and it looks like it's still connected to the Internet.
posted by bertrandom at 12:25 AM on June 6, 2008


« Older Salivafilter: Why do i keep having to swallow spit...   |   Oh hai~I can haz umploymentz? Newer »
This thread is closed to new comments.