blob: 330ba3b77732bbff50226d72f9c162752f1e0639 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# https://skogsbrus.xyz/blog/2022/06/12/router/
# https://blog.fraggod.net/2017/04/27/wifi-hostapd-configuration-for-80211ac-networks.html
{ config, lib, pkgs, secrets, ... }:
let
ifaces = config.personal.networking.interfaces;
publicSubnet = "192.168.1";
privateSubnet = "192.168.2";
in {
imports = [ ./hostapd.nix ];
options.personal.networking = {
interfaces = let
makeInterfaceOption = type:
lib.mkOption {
type = lib.types.str;
description = "Network device for the ${type} interface.";
example = "enp4s0";
};
in {
eth = makeInterfaceOption "ethernet";
wlp2ghz = makeInterfaceOption "2 GHz WiFi";
wlp5ghz = makeInterfaceOption "5 GHz WiFi";
};
};
config = {
personal.networking = {
enable = true;
ssh.enable = true;
interfaces = {
eth = "enp4s0";
wlp2ghz = "wlp5s0";
wlp5ghz = "wlp1s0";
};
};
networking = {
hostName = "kerberos";
domain = "local";
defaultGateway = {
address = "${publicSubnet}.1";
interface = ifaces.eth;
};
dhcpcd.enable = false;
interfaces = {
"${ifaces.eth}" = {
ipv4.addresses = [{
address = "${publicSubnet}.2";
prefixLength = 24;
}];
};
"${ifaces.wlp5ghz}" = {
ipv4.addresses = [{
address = "${privateSubnet}.1";
prefixLength = 24;
}];
};
};
nat = {
enable = true;
externalInterface = ifaces.eth;
internalInterfaces = [
# ifaces.wlp2ghz
ifaces.wlp5ghz
];
};
firewall.interfaces."${ifaces.wlp5ghz}" = {
allowedTCPPorts = [ 53 ];
allowedUDPPorts = [ 53 ];
};
};
services.dhcpd4 = {
enable = true;
extraConfig = ''
option subnet-mask 255.255.255.0;
option routers ${privateSubnet}.1;
option domain-name-servers ${privateSubnet}.1, 9.9.9.9;
subnet ${privateSubnet}.0 netmask 255.255.255.0 {
range ${privateSubnet}.10 ${privateSubnet}.99;
}
'';
interfaces = [ ifaces.wlp5ghz ];
};
services.unbound = {
enable = true;
settings = {
server = {
interface = [ "127.0.0.1" "${privateSubnet}.1" ];
access-control = [
"0.0.0.0/0 refuse"
"127.0.0.0/8 allow"
"${privateSubnet}.0/24 allow"
];
};
};
};
};
}
|