Skip to content

Commit

Permalink
nixos: add option for bind to not resolve local queries (#29503)
Browse files Browse the repository at this point in the history
When the user specifies the networking.nameservers setting in the
configuration file, it must take precedence over automatically
derived settings.

The culprit was services.bind that made the resolver set to
127.0.0.1 and ignore the nameserver setting.

This patch adds a flag to services.bind to override the nameserver
to localhost. It defaults to true. Setting this to false prevents the
service.bind and dnsmasq.resolveLocalQueries settings from
overriding the users' settings.

Also, when the user specifies a domain to search, it must be set in
the resolver configuration, even if the user does not specify any
nameservers.
  • Loading branch information
gwitmond authored and fpletz committed Sep 18, 2017
1 parent 3ff962d commit 670b4e2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion nixos/modules/config/networking.nix
Expand Up @@ -9,7 +9,9 @@ let
cfg = config.networking;
dnsmasqResolve = config.services.dnsmasq.enable &&
config.services.dnsmasq.resolveLocalQueries;
hasLocalResolver = config.services.bind.enable || dnsmasqResolve;
bindResolve = config.services.bind.enable &&
config.services.bind.resolveLocalQueries;
hasLocalResolver = bindResolve || dnsmasqResolve;

resolvconfOptions = cfg.resolvconfOptions
++ optional cfg.dnsSingleRequest "single-request"
Expand Down
9 changes: 9 additions & 0 deletions nixos/modules/services/networking/bind.nix
Expand Up @@ -151,6 +151,15 @@ in
";
};

resolveLocalQueries = mkOption {
type = types.bool;
default = true;
description = ''
Whether bind should resolve local queries (i.e. add 127.0.0.1 to
/etc/resolv.conf, overriding networking.nameserver).
'';
};

};

};
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/dnsmasq.nix
Expand Up @@ -42,7 +42,7 @@ in
default = true;
description = ''
Whether dnsmasq should resolve local queries (i.e. add 127.0.0.1 to
/etc/resolv.conf).
/etc/resolv.conf overriding networking.nameservers).
'';
};

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/tasks/network-interfaces-scripted.nix
Expand Up @@ -102,7 +102,7 @@ let
''
# Set the static DNS configuration, if given.
${pkgs.openresolv}/sbin/resolvconf -m 1 -a static <<EOF
${optionalString (cfg.nameservers != [] && cfg.domain != null) ''
${optionalString (cfg.domain != null) ''
domain ${cfg.domain}
''}
${optionalString (cfg.search != []) ("search " + concatStringsSep " " cfg.search)}
Expand Down

0 comments on commit 670b4e2

Please sign in to comment.