Virtual machine network configuration

1

My host OS is Ubuntu 12.04 and I am running a LAMP stack there. I have several Windows virtual machines (XP and Windows7) running in Virtual Box so I can test IE6, IE7, etc..

I frequently move this laptop between a few wireless networks and sometimes I am without an internet connection. I pause and save the VM execution state. Regardless, I want the virtual machines to be able to access the sites I am hosting locally on Ubuntu. The virtual machines do not need regular internet access. On the host I can point the browser at localhost or any subdirectory that apache is serving and view pages I've set up already. What is the best configuration for this?

Should I use Bridged or NAT virtual adaptors and should the guests use static IP's or DHCP ? I've also considered using ad-hoc networks between guests and host, but I think this will require that the host disconnect from any other networks (with internet access).

xst

Posted 2012-09-23T19:02:18.520

Reputation: 113

Answers

0

Use a NAT setup. Then you should get a virtual network where all your VMs and your host have a NIC each connected together. The host is also forwarding to the wider internet, though you don't need that. It should work transparently with connections coming and going anyway, unless some other software breaks it (NetworkManager sometimes does strange things if you use that).

Set up Apache to listen only to the virtual NIC (or it's address. I forget how Apache likes it.) and make sure to start Apache after setting up the network. Most setups will have the address of the host NIC static with a low number in the final group. The clients could use DHCP or not, whatever is easier to setup, it should not matter (you don't want the website you make to only work for specific IPs, do you?).

Stick the address of the host in the /etc/hosts file of the guest machines so you can access the server with a domain name without running or registering with a DNS server.

Edit:

Assuming you use VirtualBox as tagged, you might want to use the "Host-only" setup, as the NAT setup it makes only supports one client per network (at least it seems that way. VmWare makes the two the same way, but skips the forwarding for host-only. The same is true if you set the network up for yourself.).

Create a network in File->Preferences->Network, choose the host address and set up DHCP. Select the same network for all the guest machines. Profit.

The host NIC will show up when you run ip addr in a shell, probably named vboxnet0, ready for Apache to start listening to. You could also set up iptables forwarding if you decide you would like internet access from the VMs.

Eroen

Posted 2012-09-23T19:02:18.520

Reputation: 5 615

How do i configure the guests' hosts-file, because the address of the host will be changing often. At home it's something like 192.168.1.X (static), at the university network we get 10.X.X.X (dhcp), and like I said sometimes I have no connectivity (friends house). – xst – 2012-09-23T19:31:49.523

On the virtual network, it will be something like 192.168.159.1 and not change until you go change it yourself. The external adress of the host (which you pointed out changes) has no effect seen from the virtual network. – Eroen – 2012-09-23T19:40:02.073