authoritative_dns: configure primary/secondary zone replication #890
No files matched your search
@@ -69,6 +69,11 @@
|
|||||||
# Disable systemd-timesyncd since we're using chrony
|
# Disable systemd-timesyncd since we're using chrony
|
||||||
services.timesyncd.enable = false;
|
services.timesyncd.enable = false;
|
||||||
|
|
||||||
|
## Knot DNS - public listen address
|
||||||
|
services.knot.settings.server.listen = [
|
||||||
|
"185.240.111.53@53"
|
||||||
|
];
|
||||||
|
|
||||||
## Web services and KVM reverse proxies
|
## Web services and KVM reverse proxies
|
||||||
services.caddy = {
|
services.caddy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|||||||
@@ -25,6 +25,11 @@
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Knot DNS - public listen address
|
||||||
|
services.knot.settings.server.listen = [
|
||||||
|
"10.0.0.24@53"
|
||||||
|
];
|
||||||
|
|
||||||
# Networking
|
# Networking
|
||||||
networking = {
|
networking = {
|
||||||
interfaces.eth0 = {
|
interfaces.eth0 = {
|
||||||
@@ -38,8 +43,11 @@
|
|||||||
firewall = {
|
firewall = {
|
||||||
allowedTCPPorts = lib.mkForce [
|
allowedTCPPorts = lib.mkForce [
|
||||||
22 # SSH
|
22 # SSH
|
||||||
|
53 # DNS
|
||||||
|
];
|
||||||
|
allowedUDPPorts = lib.mkForce [
|
||||||
|
53 # DNS
|
||||||
];
|
];
|
||||||
allowedUDPPorts = lib.mkForce [ ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ in
|
|||||||
acme_dns_api = "boron.cx.${config.ogygia.domain}";
|
acme_dns_api = "boron.cx.${config.ogygia.domain}";
|
||||||
authoritative_dns = [
|
authoritative_dns = [
|
||||||
"boron.cx.${config.ogygia.domain}"
|
"boron.cx.${config.ogygia.domain}"
|
||||||
|
"cyclone.gw.${config.ogygia.domain}"
|
||||||
|
"slider.pop.${config.ogygia.domain}"
|
||||||
];
|
];
|
||||||
blackmagic-cam-importer = "phoenix.st.${config.ogygia.domain}";
|
blackmagic-cam-importer = "phoenix.st.${config.ogygia.domain}";
|
||||||
downloads = "phoenix.st.${config.ogygia.domain}";
|
downloads = "phoenix.st.${config.ogygia.domain}";
|
||||||
|
|||||||
@@ -7,6 +7,32 @@ let
|
|||||||
locations = config.custom.locations.locations;
|
locations = config.custom.locations.locations;
|
||||||
makeRecords = type: s: (lib.concatStringsSep "\n" (lib.collect builtins.isString (lib.mapAttrsRecursive (path: value: "${lib.concatStringsSep "." (lib.reverseList path)} 86400 ${type} ${value}") s)));
|
makeRecords = type: s: (lib.concatStringsSep "\n" (lib.collect builtins.isString (lib.mapAttrsRecursive (path: value: "${lib.concatStringsSep "." (lib.reverseList path)} 86400 ${type} ${value}") s)));
|
||||||
|
|
||||||
|
# Role derivation from locations
|
||||||
|
allHosts = locations.services.authoritative_dns;
|
||||||
|
primaryHost = builtins.head allHosts;
|
||||||
|
secondaryHosts = builtins.tail allHosts;
|
||||||
|
isPrimary = config.networking.fqdn == primaryHost;
|
||||||
|
isSecondary = builtins.elem config.networking.fqdn secondaryHosts;
|
||||||
|
|
||||||
|
# Nebula IP lookup (same pattern as zookeeper.nix)
|
||||||
|
lookupFqdn = fqdn:
|
||||||
|
lib.attrsets.attrByPath
|
||||||
|
(lib.reverseList (lib.splitString "." fqdn))
|
||||||
|
null
|
||||||
|
config.custom.dns.authoritative.ipv4;
|
||||||
|
|
||||||
|
primaryNebulaIp = lookupFqdn primaryHost;
|
||||||
|
secondaryNebulaIps = map lookupFqdn secondaryHosts;
|
||||||
|
|
||||||
|
# Generate remote definitions for secondaries (used on primary)
|
||||||
|
secondaryRemotes = lib.imap0
|
||||||
|
(i: ip: {
|
||||||
|
id = "secondary${toString i}";
|
||||||
|
address = "${ip}@53";
|
||||||
|
})
|
||||||
|
secondaryNebulaIps;
|
||||||
|
secondaryRemoteIds = map (r: r.id) secondaryRemotes;
|
||||||
|
|
||||||
zoneContent = ''
|
zoneContent = ''
|
||||||
$ORIGIN ${domain}.
|
$ORIGIN ${domain}.
|
||||||
$TTL 86400
|
$TTL 86400
|
||||||
@@ -20,6 +46,8 @@ let
|
|||||||
)
|
)
|
||||||
|
|
||||||
@ 86400 NS ns1.jakehillion.me.
|
@ 86400 NS ns1.jakehillion.me.
|
||||||
|
@ 86400 NS ns2.jakehillion.me.
|
||||||
|
@ 86400 NS ns3.jakehillion.me.
|
||||||
|
|
||||||
ca 21600 CNAME warlock.cx.${domain}.
|
ca 21600 CNAME warlock.cx.${domain}.
|
||||||
frigate 21600 CNAME ${locations.services.frigate}.
|
frigate 21600 CNAME ${locations.services.frigate}.
|
||||||
@@ -64,18 +92,42 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||||
|
# Common config (both primary and secondary)
|
||||||
|
{
|
||||||
custom.impermanence.extraDirs = lib.mkIf config.custom.impermanence.enable [ "/var/lib/knot" ];
|
custom.impermanence.extraDirs = lib.mkIf config.custom.impermanence.enable [ "/var/lib/knot" ];
|
||||||
|
|
||||||
services.knot = {
|
services.knot = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
acl = [{
|
server.listen = [ "${config.custom.dns.nebula.ipv4}@53" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.knot = {
|
||||||
|
after = [ "nebula@jakehillion.service" ];
|
||||||
|
requires = [ "nebula@jakehillion.service" ];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
# Primary config
|
||||||
|
(lib.mkIf isPrimary {
|
||||||
|
services.knot.settings = {
|
||||||
|
remote = secondaryRemotes;
|
||||||
|
|
||||||
|
acl = [
|
||||||
|
{
|
||||||
id = "localhost";
|
id = "localhost";
|
||||||
address = [ "127.0.0.1" "::1" ];
|
address = [ "127.0.0.1" "::1" ];
|
||||||
action = [ "update" ];
|
action = [ "update" ];
|
||||||
}];
|
}
|
||||||
|
{
|
||||||
|
id = "transfer_secondaries";
|
||||||
|
address = secondaryNebulaIps;
|
||||||
|
action = [ "transfer" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
policy = [{
|
policy = [{
|
||||||
id = "default";
|
id = "default";
|
||||||
@@ -87,7 +139,8 @@ in
|
|||||||
zone = [{
|
zone = [{
|
||||||
domain = domain;
|
domain = domain;
|
||||||
file = zoneFile;
|
file = zoneFile;
|
||||||
acl = [ "localhost" ];
|
acl = [ "localhost" "transfer_secondaries" ];
|
||||||
|
notify = secondaryRemoteIds;
|
||||||
# Don't sync changes back to the zone file (it's in the read-only Nix store)
|
# Don't sync changes back to the zone file (it's in the read-only Nix store)
|
||||||
# Dynamic updates are kept in journal only
|
# Dynamic updates are kept in journal only
|
||||||
zonefile-sync = -1;
|
zonefile-sync = -1;
|
||||||
@@ -97,6 +150,30 @@ in
|
|||||||
dnssec-policy = "default";
|
dnssec-policy = "default";
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
# Secondary config
|
||||||
|
(lib.mkIf isSecondary {
|
||||||
|
services.knot.settings = {
|
||||||
|
remote = [{
|
||||||
|
id = "primary";
|
||||||
|
address = "${primaryNebulaIp}@53";
|
||||||
|
}];
|
||||||
|
|
||||||
|
acl = [{
|
||||||
|
id = "notify_primary";
|
||||||
|
address = [ primaryNebulaIp ];
|
||||||
|
action = [ "notify" ];
|
||||||
|
}];
|
||||||
|
|
||||||
|
zone = [{
|
||||||
|
domain = domain;
|
||||||
|
master = [ "primary" ];
|
||||||
|
acl = [ "notify_primary" ];
|
||||||
|
zonefile-sync = -1;
|
||||||
|
journal-content = "all";
|
||||||
|
}];
|
||||||
};
|
};
|
||||||
};
|
})
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
@@ -310,6 +310,20 @@
|
|||||||
internalIP = "10.64.50.1";
|
internalIP = "10.64.50.1";
|
||||||
protocol = "tcp";
|
protocol = "tcp";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
description = "DNS (TCP)";
|
||||||
|
externalPort = 53;
|
||||||
|
internalIP = "10.64.50.1";
|
||||||
|
protocol = "tcp";
|
||||||
|
loopbackEnabled = false;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
description = "DNS (UDP)";
|
||||||
|
externalPort = 53;
|
||||||
|
internalIP = "10.64.50.1";
|
||||||
|
protocol = "udp";
|
||||||
|
loopbackEnabled = false;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
description = "Nebula Lighthouse";
|
description = "Nebula Lighthouse";
|
||||||
externalPort = 4242;
|
externalPort = 4242;
|
||||||
|
|||||||
Reference in new issue
Block a user