System administration for junior devs: Setting up a virtual server with Vagrant


When you’re learning about system administration, it is helpful to have a private server to muck around on so that your mistakes do not affect users. Fortunately, you can use a tool called [Vagrant]( to easily create virtual servers on your development machine. This tutorial requires Vagrant, so you will need to follow [these instructions]( if you do not have it already (it is pretty easy). You will also need [VirtualBox](

This blog post aims to help developers create a virtual server while also explaining what, exactly, that means.

### 1. Creating a clean virtual server

For this tutorial, I have predefined some _very_ vanilla Vagrant settings to get things started. To grab those, run `git clone`.

Now `cd` into that directory. `ls` and you’ll see that the repository has a `Vagrantfile` which contains details about the server that Vagrant is going to create. If you poke around that Vagrantfile and `ctrl + f` for “,” you should see a line that looks like this: ` = “ubuntu/trusty64″`. This tells Vagrant that our server should come preloaded with the [Trusty release]( of the Ubuntu operating system. You should also note that this Vagrantfile specifies a [_private IP_]( address of ``.

### 2. Creating your virtual server

We will now use Vagrant to create a virtual server on your computer. Make sure you’re in the project directory you cloned from GitHub and run `vagrant up`. (It may take a while to download the Ubuntu base image.1) Eventually your terminal should spit out something like this:

“` ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM… ==> default: Configuring and enabling network interfaces… ==> default: Mounting shared folders… “`

### 3. What it means to have a virtual server

When you run `vagrant up`, you create something that walks and talks like a real server, but it is actually running within your own computer. For our purposes, it is important that the virtual server is _networked_. We can prove it by pinging the IP referenced in the Vagrantfile (``).

“` $ ping PING ( 56 data bytes 64 bytes from icmp_seq=0 ttl=64 time=0.385 ms ^C — ping statistics — 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.385/0.385/0.385/0.000 ms “`

As you can see, we are getting packets back from the IP address we just created.

Vagrant also preloads the machine with a user named `vagrant`, and you can `ssh` into the machine as this user. Try running `vagrant ssh` from within the project directory.2 You should see a prompt like this:

“` vagrant@vagrant-ubuntu-trusty-64:~$ “`

It allows you to do everything you can do on a regular server, from checking out the machine’s OS to poking around its directory structure.

“` vagrant@vagrant-ubuntu-trusty-64:~$ uname -a Linux vagrant-ubuntu-trusty-64 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

vagrant@vagrant-ubuntu-trusty-64:~$ pwd /home/vagrant

vagrant@vagrant-ubuntu-trusty-64:~$ ls / bin dev home lib lost+found mnt proc run srv tmp vagrant vmlinuz boot etc initrd.img lib64 media opt root sbin sys usr var “`

You now have a virtual Ubuntu server running on your computer, complete with `ssh` access. `cd /` and take a little time to check out what’s going on. It might be helpful to check out this Wikipedia article on [Unix’s normal directory structure]( Many, many websites run on computers that have directories laid out like this. Don’t worry about messing some part of your server up — creating a fresh image is as easy as bringing down your existing server with `vagrant destroy` and then running `vagrant up` again. Remember that these commands (`vagrant ___`) should be issued from your computer, not from within the virtual machine.

You have now completed the first step in understanding how your server fields Web requests, creating a very basic, networked virtual server. You are controlledly replicating the Internet on your development machine. Stay tuned for part III, in which we configure our server to handle HTTP requests with NGINX.

### Extra credit

If you _really_ want to get down into the guts of what’s going on, try `ssh`ing into your virtual server and running `tcpdump -i any icmp[icmptype] == 8` to see what happens when you `ping` it. It is pretty cool!


1 The wait is more bearable when you realize you are basically downloading a whole computer!
2 It is worth noting that you did not run your system’s standard `ssh` command, but rather a Vagrant utility called `ssh` which opens a shell session on the virtual machine. You can, however, also run `ssh vagrant@` with password `vagrant`.