---
title: "Fixing Kubevirt networking not working on reboot"
date: 2024-09-26
desc: "Turns out randomizing the MAC address on boot is a bad idea"
---

When you use Ubuntu on Kubevirt like I do, rebooting a VM or manually rescheduling pods means that the MAC address in the VM changes. This makes Ubuntu's netplan very unhappy and will result in your VM not acquiring an IP address over DHCP. This is not good for uptime.

After searching the GitHub issue tracker, I found [this comment](https://github.com/kubevirt/kubevirt/issues/1646#issuecomment-433262034) from 2018 that suggested adding this netplan configuration file to the VM:

```yaml
network:
  version: 2
  ethernets:
    id0:
      dhcp4: true
      match:
        name: enp*
```

This does the trick, so my minimal cloud-init config for Ubuntu on Kubevirt VM looks like this:

```yaml
#cloud-config
hostname: noble
ssh_pwauth: True
disable_root: false

write_files:
  - encoding: b64
    content: bmV0d29yazoKICB2ZXJzaW9uOiAyCiAgZXRoZXJuZXRzOgogICAgaWQwOgogICAgICBkaGNwNDogdHJ1ZQogICAgICBtYXRjaDoKICAgICAgICBuYW1lOiBlbnAqCg==
    owner: root:root
    path: /etc/netplan/99-net-fix.yaml
    permissions: "0644"

users:
  - name: xe
    groups: [wheel]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
    ssh_import_id:
      - gh:xe
```

I've done reboot testing with my virtual machines and this seems to work consistently enough.
