views:

554

answers:

3

I am using a Macbook running 10.6. I am using VMware Fusion to run an Ubuntu Server minimal virtual machine. Ubuntu Server is running your basic LAMP stack.

I do my development in Mac OS. I have VMware share a directory from Mac OS to the Ubuntu Server. Ubuntu Server uses that directory for apache.

I access my server is Mac OS in firefox using the ip address of my virtual machine. This is a pain because I have to find out what the ip address is of my virtual machine each time I boot it up. I could set a static ip address but this causes problems if I move my Macbook from network to network.

Is there any configuration (NAT or Bridged or something) that would let me access my virtual machine from the Mac OS using localhost or something similar?

Thanks

+1  A: 

NAT should be OK. Your VM is on a different subnet that way, you can give it the static IP you like, and it won't interfere with the (dynamic) IP on your real network.

Wim
So if I set a static IP address with a NAT connection I can always access that same IP? Even when my real network changes or does not exist at all?
CT
NAT is not going to work. If the virtual machine is behind NAT, you will need some tricky routing and port-forwarding to be able to access services on it from the "outside".
Apreche
He doesn't want to access it from outside, just from the native OS on his own machine. NAT will work fine.
Wim
It's just the same as the 'host only' you suggest BTW, except that the VM can now also connect to the outside. Because if you want that in your solution, *that* will require messy routing tricks...
Wim
Will NAT work if my host OS has no internet connection?
CT
Yes, VMWare contains its own DHCP server so the VM will get its IP address (same deal for host-only networking BTW). Whether you have another (real) network or not doesn't matter.
Wim
A: 

Maybe I'm misunderstanding your question but why not just add an entry in your hosts file for the virtual machine? That way you can access it with some arbitrarily assigned name (like testmachine) instead of the IP.

This is the first tutorial I found through google: http://decoding.wordpress.com/2009/04/06/how-to-edit-the-hosts-file-in-mac-os-x-leopard/

This would work best if your VM has a static IP, BTW (either no DHCP or configure the DHCP server to give that MAC the same IP every time). That way you don't have to worry about changing the hosts entry every time the DHCP server gives the VM a different IP.

tim
This won't work that well if he takes his machine onto a different network that has a different DHCP server that gives a different IP.
Apreche
A: 

What you are looking for is the host-only networking adapter as opposed to the NAT or bridged adapters. This creates a network interface on the virtual machine that only connects the actual host. It is perfectly safe to set an IP address for this interface that does not change, and there will be no tricky NAT getting in the way. It's a little network that only exists for communication between the real host and the virtual host. It's exact purpose is so you can do development like this. I use the same feature on VirtualBox all the time, but VMWare has it as well.

Now, with a host-only adapter you might be worried that your VM now has no access to the Internet. The answer is simple. Just make two adapters. eth0, eth1. Make one of them a bridged or NAT adapter for Internet access. Make the other one the host-only adapter for your development. Most modern Linux distros will automatically route accordingly. I know for a fact that Ubuntu does, because I do it all the time. Again, this is with VirtualBox. Your mileage may vary with VMWare, but I can't imagine it's that different.

Apreche
Works fine, as long as your VM doesn't want to connect to the internet, for sending mails, getting updates, ...
Wim
If the virtual machine is Linux, you can have multiple adapters. Personally my VMS have three adapters at once. I will edit answer to accommodate.
Apreche
But why would you need two adapters, if one -- the NAT one -- is enough to both have the VM communicate with the Internet, and to have the host machine connect to the VM?
Wim