infrastructure/nixos/hosts/dns/configuration.nix

69 lines
2.2 KiB
Nix
Raw Normal View History

2021-11-21 19:30:19 +01:00
{ config, pkgs, hosts, ... }:
2021-11-21 21:56:17 +01:00
let
inherit (builtins) filter hasAttr;
2021-11-21 19:30:19 +01:00
localdomain = "olympus";
2021-11-21 21:56:17 +01:00
ipv6Hosts = filter (hasAttr "ip6") hosts;
2021-11-21 20:26:08 +01:00
2021-11-21 19:30:19 +01:00
localData = { hostname, ip, ... }: ''"${hostname}.${localdomain}. A ${ip}"'';
2021-11-21 20:26:08 +01:00
local6Data = { hostname, ip6, ... }: ''"${hostname}.${localdomain}. AAAA ${ip6}"'';
2021-11-21 19:30:19 +01:00
ptrData = { hostname, ip, ... }: ''"${ip} ${hostname}.${localdomain}"'';
2021-11-21 20:26:08 +01:00
ptr6Data = { hostname, ip6, ... }: ''"${ip6} ${hostname}.${localdomain}"'';
2021-11-21 19:30:19 +01:00
in {
imports = [ ];
networking.hostName = "dns";
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. Its perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "21.11"; # Did you read the comment?
# Additional packages
2021-11-21 21:56:17 +01:00
environment.systemPackages = with pkgs; [ dig dog drill ];
2021-11-21 19:30:19 +01:00
networking.firewall.allowedTCPPorts = [ 53 ];
networking.firewall.allowedUDPPorts = [ 53 ];
services.unbound = {
enable = true;
2021-11-21 21:56:17 +01:00
package = pkgs.v.unbound;
2021-11-21 19:30:19 +01:00
settings = {
server = {
use-syslog = "yes";
module-config = ''"validator iterator"'';
interface-automatic = "yes";
interface = [ "0.0.0.0" "::0" ];
local-zone = ''"${localdomain}." transparent'';
2021-11-21 20:26:08 +01:00
local-data = (map localData hosts) ++ (map local6Data ipv6Hosts);
2021-11-21 21:56:17 +01:00
local-data-ptr = (map ptrData hosts) ++ (map ptr6Data ipv6Hosts);
2021-11-21 19:30:19 +01:00
access-control = [
"127.0.0.1/32 allow_snoop"
"::1 allow_snoop"
"10.42.0.0/16 allow"
"127.0.0.0/8 allow"
"192.168.2.0/24 allow"
"::1/128 allow"
];
private-address = [
"127.0.0.0/8"
"10.0.0.0/8"
"::ffff:a00:0/104"
"172.16.0.0/12"
"::ffff:ac10:0/108"
"169.254.0.0/16"
"::ffff:a9fe:0/112"
"192.168.0.0/16"
"::ffff:c0a8:0/112"
"fd00::/8"
"fe80::/10"
];
};
};
};
}