Virtualbox networking: Windows host, Debian guest

After a lot of farting around with different virtual network adapter types and use cases I finally settled on a networking configuration that works well for developing web apps inside a Debian Virtual Machine running inside Virtualbox on my Windows laptop.

The problem:

  • VM needs to be accessible by the windows host even when laptop is “offline” so I can work on the plane.
  • When laptop is “online”, VM can also access the internet
  • VM should be accessed by host via a static IP address so that dev environment settings persist beyond a reboot

The Solution:

  1. Two virtual network adapters in the VM’s network tab in Virtualbox:
    • Adapter #1: “NAT” / DHCP
    • Adapter #2: “Host-only” / Static IP

    The NAT adapter should already be set up by default when you do a fresh install of Debian in Virtualbox. It enables the VM to access the wider internet.

    Meanwhile the Host-only adapter enables the host machine to see the VM and persists even when internet connectivity drops allowing you to carry on working.

  2. Set up the Virtualbox Host-only network.

    Click File > Preferences > Network, then select “Virtualbox Host-only ethernet adapter” (or whichever host only adapter you selected in the VM’s host-only network adapter tab). Click the edit button which looks like a screwdriver. Enter an unused network in the 192.168.x.x Ip range. I’m using 213.1 because my router is on 192.168.0.1, but I could use anything in that 3rd octet except 0 I think. The netmask should be 255.255.0.0 but for some reason it still works with 255.255.255.0 – I’m still not quite sure why that is though.

    Click the “DHCP server” tab and uncheck the ‘Enable Server’ checkbox – we don’t need DHCP because we’ll be using a static IP address.

  3. Configure the networking inside the VM

    Log into the VM as root and edit /etc/network/interfaces – it should look like this:

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The NAT virtual adapter
    allow-hotplug eth0
    iface eth0 inet dhcp

    # The Host-only virtual adapter
    auto eth1
    iface eth1 inet static
    address 192.168.213.9 # this must match Virtualbox host-only network
    netmask 255.255.255.0

  4. Reset the VM and you should now be up and running

Migrate a site or folder tree recursively over FTP via the command line (ncftp)

Problem:

  • You are moving a web site or folder tree from one computer to another via FTP
  • The source computer is Linux
  • You can’t use the basic FTP program because it doesn’t recurse directories

Solution:
Use ncftp. Install it if necessary, cd to the root of the folder you want to put to the FTP server and then run the following command:
ncftpput -u myFTPusername -p myFTPpassword -R myftp.server.com .

Creating a large storage volume on a Linux VM running on an ESXi host

I have an ESXi host in my office with a RAiD10 array that has around 925GB in capacity – 95% unused. I have a couple of VMs on it that hardly use any of that space and I wanted to make use of all the spare storage space to make a backup of our family photos which were previously stored on two 500GB external drives and take up over 700GB. That’s quite a lot isn’t it? … you might say. Well, I agree, but my wife is rather trigger happy and loves to take 10 slightly different versions of the same shot so that she can choose the best one…. unfortunately the choosing of the best ones rarely involves deleting more than 1 out of each 10 of what was taken, hence the monstrously large library. Ah well!
Continue reading