I lucked into some new server hardware (read my wife’s gaming machine bit the dust). As such, I decided to move my dev servers up to Ubuntu 18.04. My plan this time is to containerize some of my services like dhcp and dns, but also use kvm to host virtual machines for testing purposes. As such, the first step for me was to install Ubuntu and get KVM working.

Pre-Req’s

Firstly, I went into bios and enabled virtualization on this machine. Next I booted off of a 18.04 USB ISO I downloaded from the internets. The install for 18 Server is super simple and straightforward. And then I immediately ran into a problem trying to set my static network interfaces. Apparently they moved to NetPlan as part of the change to 18. After some quick googling, I found that this is actually a simpler file than my trusted /etc/network/interface file I had really wanted to edit. On my machine, I simply created and edited a file /etc/netplan/01-netcfg.yaml to the following. YMMV - seriously, yaml is not forgiving on formatting, so copy and paste may not work the way you expect.

# The primary network interface
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
   version: 2
   renderer: networkd
   ethernets:
     eno1:
       dhcp4: no
       dhcp6: no
       addresses: [192.168.80.13/24]
       gateway4: 192.168.80.1
       nameservers:
         addresses: [151.197.0.37,198.6.1.3,71.242.0.12]

Setup the Bridge network

To make any of this work, the host machine will need to have a bridge network to connect the network that the guests are using with the actual network the host is physically connected to. Therefore my first step is to setup a bridge network on the host.

Installing the bridge utility:

sudo apt install bridge-utils

Run ifconfig to validate network interface name - mine is eno1

ifconfig

Now I am going to nano /etc/netplan/01-netcfg.yaml again and edit it to the below. If you read through this, all I am doing is adding a new bridge and some specific settings like which physical interface the bridge should use (in my case it is eno1). I also removed all of the settings from the main network interface and moved them to the bridge itself.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
   version: 2
   renderer: networkd
   ethernets:
     eno1:
       dhcp4: no
       dhcp6: no
   bridges:
     br0:
       interfaces: [eno1]
       dhcp4: no
       dhcp6: no
       addresses: [192.168.80.13/24]
       gateway4: 192.168.80.1
       nameservers:
         addresses: [151.197.0.37,198.6.1.3,71.242.0.12]
       parameters:
         stp: false
         forward-delay: 0

To actually get this working I now need to restart a number of services. I am sure there is a more nuanced way to do this, but I find it easiest to simply reboot.

sudo reboot now

Install KVM

My next step is to install kvm itself as well as the management tools I will be using.

sudo apt install qemu-kvm libvirt-bin

This was a long install as there are a lot of dependencies I didn’t already have on this fresh server install. Once finished, I had to log out and log back in to my ssh session to be able to run virsh without sudo. This is because the installation process added my account to the libvertd group, but it isn’t effective until you relogin.

Validate Install

Firstly I just wanted to make sure it was running, so I ran a basic listing of virtual machines and successfully returned nothing. Woot!

$ virsh list
 Id    Name                           State
----------------------------------------------------

Next I wanted to spin up a guest just to see if everything was working. I downloaded an ubuntu iso into my images folder and then spun up a test machine using Virtual Machine Manager connected in from a client machine.

wget http://releases.ubuntu.com/18.04/ubuntu-18.04.1-live-server-amd64.iso ~/images/

I then simply ran updates on the new guest machine just to make sure network connectivity was working as expected.

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt autoremove

It all looked good at this point, so I went ahead and shutdown my test guest.

Credits:

Webby Land has a good write up on the changes in Ubuntu networking and how to setup the bridge in 18.04.

Ubuntu kvm setup is an older post I wrote about this same process in 16.04. The credits for that one are below:

Narrow Escape has a great write up on Bridged Networking options for Ubuntu 16.04. nixCraft has a great write up on the entire process and has a number of useful references for using virt-install. Narrow Escape also has a great guide, but slightly aimed at a more gui based user. Ubunut KVM Installation this has a lot of useful info - definitely worth keeping this page up during your installation.