How to use a nameserver with a static networking configuration?

Hi,

I’m not sure if what I’m encountering is a bug (so I’m first asking here before creating a github issue).

I currently have problems with resolving domains on my server (which runs on NixOS 20.09), probably best explained by the config:

...
  networking = {
    useDHCP = false;
    interfaces.ens3.useDHCP = false;
    interfaces.ens3.ipv4.addresses = [{
      address = "<myaddress>";
      prefixLength = 22;
    }];
    defaultGateway = "<mygateway>";
    nameservers = [ "1.1.1.1" "8.8.8.8" "8.8.4.4" ];
    hostName = "<myhostname>";
  }
...

This is I guess the relevant section I’ve configured.
I thought that the nameservers are generated into the resolv.conf (which I manually put in to test, which fixed my issue with dns resolving).

But it seems there is no nameserver added into the /etc/resolv.conf with this configuration.
On my desktop configuration, where I’m using Networkmanager and DHCP /etc/resolv.conf is correctly injecting the nameservers I’ve configured in networking.nameservers.

1 Like

Ok, I’ve found my issue:

I’m also using simple-nixos-mailserver / nixos-mailserver · GitLab
which is configured by default with this: localDnsResolver = true, this replaces the nameservers config with [ "127.0.0.1" ] and thus all my nameservers are gone and replaced with localhost.
I’ve set it to false for now, which fixes my issue.

I’ve created an issue in nixos-mailserver, if anyone else is running into this:

Thanks for this! My server couldn’t resolve any hostnames anymore, and this thread helped me identify simple-nixos-mailserver as the problem. I’m guessing localDnsResolver = true interferes with getting nameservers from DHCP.