Before setting up a new server on a live machine it can sometimes be useful to set up a virtual machine in order to test the configuration. This will allow you to play around with settings and even make mistakes without causing harm to a real system. I like to do this so I can change things over and over until it’s just right, then I can copy the final configuration over to the live system. In this example I will set up a Debian 9 virtual server in Oracle VirtualBox and configure so it can be accessed by the host machine and over a LAN. This means the configuration can be tested from different devices.
Step 1: Install VirtualBox
I won’t cover this in detail. I found installation quite straightforward. VirtualBox is available for Windows, OS X, Solaris and various Linux distributions. The instructions for installing various operating systems can be found here.
Step 2: Download server installation image
The installation page for Debian is located here. There are various methods but most people with a decent internet connection will want to download a small installation image and then download the rest of the packages from the internet. I chose small installation image then selected the amd64 small image.
Step 3: Setting up the virtual server
Start VirtualBox and select new.

Give you machine a name, and select the Debian Version from the drop down. Then create a new virtual hard disk, using the default settings should be fine here.
After this, select the settings for your new VM. Under Storage you will see a CD drive which is empty.

Under Attributes, change the Optical Drive to the Debian image your downloaded earlier.
Step 4: Installing the virtual machine operating system
Click ok and you are ready to start your VM. Run through the installation process. In most cases the Debian defaults will be fine.
At the software selection page I deselected the Debian desktop environment option and selected web server because I am setting it up as a headless web server.
Following installation the machine should boot into the installed version. Press the alt key to ‘break out’ of the VM and return to the host operating system.
I installed ssh via:
# apt-get install ssh
You can also find the machine’s ip address by typing:
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:89:08:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.10.2/24 brd 192.168.4.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe89:8ae/64 scope link
valid_lft forever preferred_lft forever
The ip address is 192.168.10.2. You can try to ssh into the machine from the host OS. Also type the ip address into a web browser and confirm that you can see the default apache web page.
Poweroff the machine and then restart in headless mode. Open a terminal on the host machine and type:
$ VBoxHeadless -s testy Oracle VM VirtualBox Headless Interface 5.2.18_Debian (C) 2008-2018 Oracle Corporation All rights reserved.
You can now ssh into the machine as before and configure your virtual server in a safe test environment before rolling it out for real. Try accessing the web server from a phone or tablet connected to the same network.
Some improvements
You could add the ip address to your /etc/hosts file in order to make access it easier. In the future I am going to set up dnsmasq on my network so other devices can also type a hostname instead of an ip address.
If you think the ip address is going to change frequently then you can find the virtual machine’s mac address under the Network section of settings. Click advanced to show it. You can then configure your DHCP server to allocate a fixed ip address to the VM.
This is fairly basic run through of the setup. In another article I will cover some alternate configurations and other ways of running a VM test server.
