How to configure DNS per container - /etc/resolv.conf

How do i configure the DNS of a specific container and retain those changes so that it doesn’t inherit the /etc/resolv.conf from the incus host?

The default setup for an Incus container is to use the managed incusbr0 bridged private network. In that network, your containers are configured automatically with DHCP to get their network settings from the dnsmasq process that listens on incusbr0. The dnsmasq process is also a caching nameserver, and passes and DNS requests to whatever the host uses for DNS resolutions.

Therefore, if you want to use a different DNS server for a container, you can use the tools of a container to switch DNS server. For example, resolvectl is one such tool.

If you want to forbid the container from ever finding out the host’s DNS server, there are a few things you can do here. Depending on your requirements, you may create a new Incus managed network (incus network create ...) that uses some other DNS server, and configure those container to use this new managed network interface.

To use that new managed interface (let’s call it incusbr1), you can also create a new Incus profile that uses the incusbr1 interface. In that case, you would launch containers with

incus launch images:ubuntu/22.04 mycontainer --profile default --profile thisnetworkplease

This supplementary Incus profile would look like this. And thanks to Incus profile stacking, the specific common configuration for eth0 will come from the supplementary Incus profile, while the other settings from the default profile stay the same.

devices:
  eth0:
    name: eth0
    network: incusbr1
    type: nic

Thanks for you reply. I should have specified I’m using macvlan network type. I will take another look. The file is maybe being updated by dhcp after I change it.

When you use macvlan in Incus, your instances either get a DHCP request from the specified network interface (not managed by Incus), or are configured manually (which is not the case for your setup).