Set global DNS server in snap


Is it possible to set the global DNS server in a snap?

I know that by using systemd-resolved D-BUS API, it would work to set a DNS server for a specific link (tbh, I haven’t tried), according the the comment in interfaces/builtin/network_control.go:

# Allow access to the safe members of the systemd-resolved D-Bus API:
# This API may be used directly over the D-Bus system bus or it may be used
# indirectly via the nss-resolve plugin:

Another thought is to use system-files interface and write the DNS config file to /etc/systemd/resolved.conf.d/.


Indeed, network-control does not expose a way to permanently change DNS configuration. AFAIU the SetLinkDNS is only temporary. Looking at the docs at the intention is for it to be called by network management software. probably the likes of systemd-networkd/NeworkManager once they get the DNS servers via DHCP.

I think that maybe you could probably produce a config for netplan which sets the DNS servers in the system. This is allowed by using network-setup-control interface.

However, I don’t think there’s a way to set DNS=... in resolved.conf without using system-files. Though, the net effect is probably identical if you just specify the same list of DNS servers in nameservers for each interface.