Using a custom DNS


In some scenarios the default of using the system-provided DNS will not be sufficient. When that’s the case, you can use the --cloud-init option to the launch command, or modify the networking configuration after the instance started.

The --cloud-init approach


To use a custom DNS in your instances, you can use this cloud-init snippet:

#cloud-config
bootcmd:
- printf "[Resolve]\nDNS=8.8.8.8" > /etc/systemd/resolved.conf
- [systemctl, restart, systemd-resolved]

Replace 8.8.8.8 with whatever your preferred DNS server is. You can then launch the instance using the following:

$ multipass launch --cloud-init systemd-resolved.yaml

The netplan.io approach


After the instance booted, you can modify the /etc/netplan/50-cloud-init.yaml file, adding the nameservers entry:

network:
  ethernets:
    ens3:
      dhcp4: true
      match:
        macaddress: 52:54:00:fe:52:ee
     set-name: ens3
     nameservers:
       search: [mydomain]
       addresses: [8.8.8.8]

You can then test it:

$ sudo netplan try
Do you want to keep these settings?


Press ENTER before the timeout to accept the new configuration


Changes will revert in 120 seconds
...

Last updated 9 days ago.