How to use 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:

- printf "[Resolve]\nDNS=" > /etc/systemd/resolved.conf
- [systemctl, restart, systemd-resolved]

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

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

The approach

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

      dhcp4: true
        macaddress: 52:54:00:fe:52:ee
     set-name: ens3
       search: [mydomain]
       addresses: []

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
1 Like