Can't override DHCP DNS

Hi, I want to override the DNS Server that is set via DHCP by the VPS-Hoster, so that it can reach my other internal servers with their private DNS-hostnames.

Now I’ve tried a couple combinations of the following options but still the DNS servers at the top of /etc/resolv.conf are the ones provided by DHCP.
networking = {
dhcpcd.extraConfig = “nohook resolv.conf”;
networkmanager = {
enable = true;
#insertNameservers = [
};
nameservers = [
“the private IP of my DNS server”
“1.1.1.1”
“1.0.0.1”
“8.8.8.8”
“8.8.4.4”
];
};

Are you using NetworkManager or dhcpcd?

Apparently I am using both, since dhcpcd is enabled by default.

But I finally managed to find the right combination. I’m not sure yet which parts I can leave out, I got it working 2 mins ago but the following config puts the DNS servers specified in insertNameservers at the top of resolv.conf.

networking = {
dhcpcd = {
enable = true;
extraConfig = “nohook resolv.conf”;
};
networkmanager = {
enable = true;
dhcp = “dhcpcd”;
insertNameservers = [
#};
#nameservers = [
];
};
};

Actually you changed it: the default is networking.networkmanager.dhcp = "internal"; which means NetworkManager will use its own DHCP client.

I have no idea how or whether using an external program (dhcpcd in this case) works in NixOS: the option is completely untested and undocumented. At best it will ignore networking.dhcpcd.extraConfig, since those options are not linked to /etc/, but only affect the dhcpcd.service unit.

Unless you’re have a specific reason to do so, I’d advise to use the default.

I’ll leave it as is for the moment.