Getting host-only networking with VirtualBox working on Arch Linux

On Arch Linux, host-only networking on VirtualBox does not work for me out of the box. The vboxnetX device is not set up correctly, so connecting to the host machine is not possible.

In order to fix this, I have to run the following script after firing up a virtual machine:

#!/bin/sh
DEV=$(ip link | grep vbox | tail -n1 | awk -F': ' '{ print $2 }')

set -e

sudo ip link set dev $DEV up
sudo ip addr add 172.17.8.1 dev $DEV
sudo ip route change 172.17.8.0/24 dev $DEV

Just run it after vagrant up.

This seems awkward. There must be a better way of doing this through systemd configuration?