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:

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

set -e

sudo ip link set dev $DEV up
sudo ip addr add dev $DEV
sudo ip route change dev $DEV

Just run it after vagrant up.

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