]> Git — Sourcephile - sourcephile-nix.git/blob - machines/mermet/networking/nftables.nix
environment: add networking tools
[sourcephile-nix.git] / machines / mermet / networking / nftables.nix
1 { pkgs, lib, config, machines, ... }:
2 let
3 inherit (builtins) hasAttr readFile;
4 inherit (pkgs.lib) unlinesAttrs;
5 inherit (config.users) users groups;
6 in
7 {
8 networking.firewall.enable = false;
9 security.lockKernelModules = false;
10 systemd.services.disable-kernel-module-loading.after = [ "nftables.service" ];
11 # echo -e "$(nix eval machines.losurdo.config.networking.nftables.ruleset)"
12 # nft list ruleset
13 networking.nftables = {
14 enable = true;
15 ruleset = lib.mkBefore ''
16 table inet filter {
17 chain net2fw {
18 # Some .nix append rules here with: add rule inet filter net2fw ...
19 }
20 chain fw2net {
21 tcp dport {80,443} counter accept comment "HTTP"
22 udp dport 123 skuid ${users.systemd-timesync.name} counter accept comment "NTP"
23 tcp dport 9418 counter accept comment "Git"
24
25 # Some .nix append rules here with: add rule inet filter fw2net ...
26 }
27 chain lan2fw {
28 accept
29 # Some .nix append rules here with: add rule inet filter lan2fw ...
30 }
31 chain fw2lan {
32 accept
33 # Some .nix append rules here with: add rule inet filter fw2lan ...
34 }
35 chain intra2fw {
36 # Some .nix append rules here with: add rule inet filter intra2fw ...
37 }
38 chain fw2intra {
39 # Some .nix append rules here with: add rule inet filter fw2intra ...
40 }
41
42 chain input {
43 type filter hook input priority 0
44 policy drop
45
46 iifname lo accept
47
48 # accept traffic already established
49 ct state {established, related} accept
50 ct state invalid drop
51
52 # admin services
53 tcp dport 22 counter accept comment "SSH"
54 udp dport 60000-61000 counter accept comment "Mosh"
55
56 # ICMP
57 #ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, mld-listener-query, nd-router-solicit } accept
58 ip protocol icmp icmp type { destination-unreachable, router-advertisement, time-exceeded, parameter-problem } accept
59
60 # allow "ping"
61 #ip6 nexthdr icmpv6 icmpv6 type echo-request accept
62 ip protocol icmp icmp type echo-request accept
63
64 # Some .nix append gotos here with: add rule inet filter input iffname ... goto ...
65 }
66 chain output {
67 type filter hook output priority 0
68 policy drop
69
70 oifname lo accept
71
72 ct state {related,established} accept
73 ct state invalid drop
74
75 icmp type echo-request counter accept comment "Ping"
76 tcp dport 22 counter accept comment "SSH"
77
78 # Some .nix append gotos here with: add rule inet filter output oifname ... goto ...
79 }
80 chain forward {
81 type filter hook forward priority 0
82 policy drop
83 drop
84 }
85 }
86 '';
87 };
88 }