2024-02-15 13:38:30 +01:00
|
|
|
# SPDX-FileCopyrightText: 2023-2024 Simon Bruder <simon@sbruder.de>
|
2024-01-06 01:19:35 +01:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2023-10-18 20:12:41 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-09-24 14:41:22 +02:00
|
|
|
let
|
2023-10-18 20:04:04 +02:00
|
|
|
cfg = pkgs.callPackage ./common.nix { };
|
2023-09-24 14:41:22 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
services.dnsmasq = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
bogus-priv = true; # do not forward revese lookups of internal addresses
|
|
|
|
domain-needed = true; # do not forward names without domain
|
2023-10-18 20:12:41 +02:00
|
|
|
interface = lib.mapAttrsToList (name: config: "br-${name}") cfg.vlan; # only respond to queries from own interfaces
|
2023-09-24 14:41:22 +02:00
|
|
|
no-hosts = true; # do not resolve hosts from /etc/hosts
|
|
|
|
no-resolv = true; # only use explicitly configured resolvers
|
2023-10-18 20:12:41 +02:00
|
|
|
dhcp-fqdn = true; # only insert qualified names of DHCP clients into DNS
|
2023-09-24 14:41:22 +02:00
|
|
|
|
|
|
|
cache-size = 10000;
|
|
|
|
|
2023-10-18 20:12:41 +02:00
|
|
|
domain = [
|
|
|
|
"invalid.sbruder.de" # used when no rule below matches
|
|
|
|
] ++ (lib.flatten (lib.mapAttrsToList
|
|
|
|
(name: { domain, subnet, ... }: [
|
|
|
|
"${domain},br-${name}" # only this is not enough
|
|
|
|
"${domain},${subnet.v4.cidr}"
|
|
|
|
"${domain},${subnet.v6.cidr}"
|
|
|
|
])
|
|
|
|
cfg.vlan));
|
2023-09-24 14:41:22 +02:00
|
|
|
|
|
|
|
# Allow resolving the router
|
2023-10-18 20:12:41 +02:00
|
|
|
interface-name = lib.mapAttrsToList (name: { domain, ... }: "${config.networking.hostName}.${domain},br-${name}") cfg.vlan;
|
2023-09-24 14:41:22 +02:00
|
|
|
|
2023-10-18 20:12:41 +02:00
|
|
|
dhcp-range = lib.flatten (lib.mapAttrsToList
|
|
|
|
(name: { subnet, ... }: [
|
|
|
|
"tag:br-${name},${subnet.v4.withoutLastComponent}2,${subnet.v4.withoutLastComponent}254,12h" # DHCPv4
|
|
|
|
"tag:br-${name},${subnet.v6.net},ra-stateless,ra-names" # SLAAC (for addresses) / DHCPv6 (for DNS)
|
|
|
|
])
|
|
|
|
cfg.vlan);
|
|
|
|
dhcp-option = lib.flatten (lib.mapAttrsToList
|
|
|
|
(name: { subnet, ... }: [
|
2024-02-15 13:38:30 +01:00
|
|
|
# Gateway
|
2023-10-18 20:12:41 +02:00
|
|
|
"tag:br-${name},option:router,${subnet.v4.gateway}"
|
|
|
|
"tag:br-${name},option6:dns-server,${subnet.v6.gateway}"
|
2024-02-15 13:38:30 +01:00
|
|
|
|
|
|
|
# NTP server (runs on gateway)
|
|
|
|
"tag:br-${name},option:ntp-server,${subnet.v4.gateway}"
|
|
|
|
"tag:br-${name},option6:ntp-server,${subnet.v6.gateway}"
|
2023-10-18 20:12:41 +02:00
|
|
|
])
|
|
|
|
cfg.vlan);
|
2023-09-24 14:41:22 +02:00
|
|
|
|
|
|
|
server = [
|
|
|
|
"127.0.0.1#5053"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.dnsmasq.after = [ "systemd-networkd.service" ];
|
|
|
|
|
|
|
|
networking.firewall.allowedUDPPorts = [ 53 67 ];
|
|
|
|
networking.firewall.allowedTCPPorts = [ 53 ];
|
|
|
|
|
|
|
|
services.prometheus.exporters.dnsmasq = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = config.sbruder.wireguard.home.address;
|
|
|
|
leasesPath = "/var/lib/dnsmasq/dnsmasq.leases";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.https-dns-proxy = {
|
|
|
|
enable = true;
|
|
|
|
provider = {
|
|
|
|
kind = "custom";
|
|
|
|
ips = [ "9.9.9.9" "149.112.112.112" ];
|
|
|
|
url = "https://dns.quad9.net/dns-query";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|