feat: define dhcp settings and subnets etc

This commit is contained in:
Ahwx 2025-06-03 10:33:55 +02:00
parent f113d19c33
commit da80328deb
2 changed files with 138 additions and 49 deletions

View file

@ -11,6 +11,24 @@ let
# internalIPs = lib.mapAttrsToList ( # internalIPs = lib.mapAttrsToList (
# _: val: lib.strings.removeSuffix ".1" val.cidr + ".0/24" # _: val: lib.strings.removeSuffix ".1" val.cidr + ".0/24"
# ) networks; # ) networks;
commonDhcpOptions = [
{
name = "domain-name-servers";
data = "9.9.9.9";
}
{
name = "time-servers";
data = "172.16.1.1";
}
{
name = "domain-name";
data = "beeping.local";
}
{
name = "domain-search";
data = "beeping.local";
}
];
in in
{ {
imports = [ imports = [
@ -51,7 +69,26 @@ in
}; };
}; };
# label network interfaces
services.udev.extraRules = ''
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:47:67:6e", ATTR{type}=="1", NAME="wan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:47:67:6f", ATTR{type}=="1", NAME="lan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:63:0f:80", ATTR{type}=="1", NAME="lan1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:63:0f:81", ATTR{type}=="1", NAME="lan2"
'';
networking = { networking = {
nameservers = [
"9.9.9.9"
"149.112.112.112"
];
interfaces = {
wan0.useDHCP = true;
lan0.useDHCP = false;
lan1.useDHCP = false;
lan2.useDHCP = false;
};
firewall = { firewall = {
enable = false; enable = false;
allowPing = true; allowPing = true;
@ -101,14 +138,15 @@ in
}; };
services = { services = {
udev.extraRules = '' kea.dhcp4 = {
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:47:67:6e", ATTR{type}=="1", NAME="wan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:47:67:6f", ATTR{type}=="1", NAME="lan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:63:0f:80", ATTR{type}=="1", NAME="lan1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:63:0f:81", ATTR{type}=="1", NAME="lan2"
'';
dhcpd4 = {
enable = true; enable = true;
settings = {
lease-database = {
name = "/var/lib/kea/dhcp4.leases";
persist = true;
type = "memfile";
};
interfaces-config = {
interfaces = [ interfaces = [
"lan" "lan"
"servers" "servers"
@ -116,41 +154,92 @@ in
"iot" "iot"
"guest" "guest"
]; ];
extraConfig = '' };
option domain-name-servers 9.9.9.9, 149.112.112.112; option-data = [
option subnet-mask 255.255.255.0; {
name = "domain-name-servers";
data = "";
always-send = true;
}
{
name = "routers";
data = "";
}
{
name = "domain-name";
data = "beeping.local";
}
];
subnet 172.16.1.0 netmask 255.255.255.0 { rebind-timer = 2000;
option broadcast-address 172.16.1.255; renew-timer = 1000;
option routers 172.16.1.1; valid-lifetime = 43200;
interface lan;
range 172.16.1.50 172.16.1.254; # option domain-name-servers 9.9.9.9, 149.112.112.112;
# TODO: these should be dynamically generated based on ${config.networking.vlans}
subnet4 = [
({
id = 1;
interface = "lan";
subnet = "172.16.1.0/24";
pools = [ { pool = "172.16.1.50 - 172.16.1.254"; } ];
option-data = [
{
name = "routers";
data = "172.16.1.1";
} }
subnet 172.16.10.0 netmask 255.255.255.0 { ] ++ commonDhcpOptions;
option broadcast-address 172.16.10.255; })
option routers 172.16.10.1; ({
interface servers; id = 10;
range 172.16.10.50 172.16.10.254; interface = "servers";
subnet = "172.16.10.0/24";
pools = [ { pool = "172.16.10.50 - 172.16.10.254"; } ];
option-data = [
{
name = "routers";
data = "172.16.10.1";
} }
subnet 172.16.21.0 netmask 255.255.255.0 { ] ++ commonDhcpOptions;
option broadcast-address 172.16.21.255; })
option routers 172.16.21.1; ({
interface management; id = 21;
range 172.16.21.50 172.16.21.254; interface = "management";
subnet = "172.16.21.0/24";
pools = [ { pool = "172.16.21.50 - 172.16.21.254"; } ];
option-data = [
{
name = "routers";
data = "172.16.21.1";
} }
subnet 172.16.100.0 netmask 255.255.255.0 { ] ++ commonDhcpOptions;
option broadcast-address 172.16.100.255; })
option routers 172.16.100.1; ({
interface iot; id = 100;
range 172.16.100.50 172.16.100.254; interface = "iot";
subnet = "172.16.100.0/24";
pools = [ { pool = "172.16.100.50 - 172.16.100.254"; } ];
option-data = [
{
name = "routers";
data = "172.16.100.1";
} }
subnet 172.16.110.0 netmask 255.255.255.0 { ] ++ commonDhcpOptions;
option broadcast-address 172.16.110.255; })
option routers 172.16.110.1; ({
interface guest; id = 110;
range 172.16.110.50 172.16.110.254; interface = "guest";
subnet = "172.16.110.0/24";
pools = [ { pool = "172.16.110.50 - 172.16.110.254"; } ];
option-data = [
{
name = "routers";
data = "172.16.110.1";
} }
''; ] ++ commonDhcpOptions;
})
];
};
}; };
avahi = { avahi = {
enable = true; enable = true;

View file

@ -2,7 +2,7 @@
{ {
services = { services = {
dnsmasq = { dnsmasq = {
enable = true; enable = false; # try some other options first
settings = { settings = {
cache-size = 10000; # Specifies the size of the DNS query cache. It will store up to n cached DNS queries to improve response times for frequently accessed domains. cache-size = 10000; # Specifies the size of the DNS query cache. It will store up to n cached DNS queries to improve response times for frequently accessed domains.
server = [ server = [