VirtualBox Linux Guest Notes

6 minute read

Notes on how to configure Linux as a guest operating system in a VirtualBox virtual machine.

Note: Most of these notes apply for all Linux distros but some might be Debian specific.

Configure virtual machine networks to host and test multiple websites

The virtual machine should be configured with two network interfaces, one as NAT to allow access to the Internet from within the guest operating system (OS) using the host Internet connection and the other as a Host-only Adapter to create a host/guest internal network over which you can test access to the websites and applications hosted on Apache. In this example, the IP of the virtual machine on the host-only adapter is going to be and the IP of the host will be

On the virtual machine, edit /etc/hosts to set up the IP for the virtual sites, so that you can test them from within a web browser from the virtual machine OS. For example, it should look like so:	localhost	debian-laptop.local	debian-laptop

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


To access and test the websites from the host OS you need to update the hosts file of the host OS. If the host OS is Microsoft Windows the hosts file can be found in C:\Windows\System32\drivers\etc\hosts.

Refresh the network interface - required when virtual machine is connecting through a new physical network.

If you are using your virtual machine in one place, say at work, and then suspend and resume work at home or someplace else, you might find that the virtual machine cannot connect to the Internet. This happens because the network interface of the virtual machine using NAT is still looking for the physical network at your previous location that is no longer available. To get it working again, you need to reset the virtual machine network interface to connect through the new physical network present in your new location, as shown below.

sudo ifdown eth0
sudo ifup eth0

Installing VirtualBox guest additions

Follow these steps to install the Guest Additions on your Debian virtual machine:

  1. Login as root
  2. Update your APT database with apt-get update
  3. Install the latest security updates with apt-get upgrade
  4. Install required packages with apt-get install build-essential module-assistant
  5. Configure your system for building kernel modules by running m-a prepare
  6. Click on Install Guest Additions… from the Devices menu, then run mount /media/cdrom
  7. Run sh /media/cdrom/, and follow the instructions on screen.

Mounting a VirtualBox shared folder

First install the VirtualBox guest additions on the virtual machine to enable shared folder support amongst other features.

Then use VirtualBox to set up a shared folder, giving it a name, say, share.

Finally, edit the /etc/rc.local to automatically mount the shared folder at boot up time by adding an entry such as mount -t vboxsf share /home/user/host, where share is the name you gave to the shared folder and /home/user/host is the location where you want to mount this shared folder on the guest machine.


Ensuring date / time sync with host on a guest linux virtual machine

  1. Ensure NTP daemon is installed and running. If not use sudo apt-get install ntp.
  2. Next edit the NTP configuration file: sudo nano /etc/ntp.conf
  3. Set the first configuration line to tinker panic 0 so that NTP will ignore large differences in time between guest and host, and sync appropriately when the virtual machine is resumed. These time differences occur when a virtual machine is paused and resumed hours or days later.

If the above steps still do not help, after resuming the virtual machine you could run sudo service ntp restart.