|
21 | 21 | }; |
22 | 22 | networking.nftables.ruleset = mkOption { |
23 | 23 | type = types.lines; |
24 | | - default = |
25 | | - '' |
26 | | - table inet filter { |
27 | | - # Block all IPv4/IPv6 input traffic except SSH. |
28 | | - chain input { |
29 | | - type filter hook input priority 0; |
30 | | - ct state invalid reject |
31 | | - ct state {established, related} accept |
32 | | - iifname lo accept |
33 | | - tcp dport 22 accept |
34 | | - reject |
35 | | - } |
| 24 | + example = '' |
| 25 | + # Check out https://wiki.nftables.org/ for better documentation. |
| 26 | + # Table for both IPv4 and IPv6. |
| 27 | + table inet filter { |
| 28 | + # Block all incomming connections traffic except SSH and "ping". |
| 29 | + chain input { |
| 30 | + type filter hook input priority 0; |
36 | 31 |
|
37 | | - # Allow anything in. |
38 | | - chain output { |
39 | | - type filter hook output priority 0; |
40 | | - ct state invalid reject |
41 | | - ct state {established, related} accept |
42 | | - oifname lo accept |
43 | | - accept |
44 | | - } |
| 32 | + # accept any localhost traffic |
| 33 | + iifname lo accept |
45 | 34 |
|
46 | | - chain forward { |
47 | | - type filter hook forward priority 0; |
48 | | - accept |
49 | | - } |
50 | | - } |
51 | | - ''; |
52 | | - example = |
53 | | - '' |
54 | | - # Check out http://wiki.nftables.org/ for better documentation. |
| 35 | + # accept traffic originated from us |
| 36 | + ct state {established, related} accept |
55 | 37 |
|
56 | | - define LAN = 192.168.0.1/24 |
| 38 | + # ICMP |
| 39 | + # routers may also want: mld-listener-query, nd-router-solicit |
| 40 | + ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert } accept |
| 41 | + ip protocol icmp icmp type { destination-unreachable, router-advertisement, time-exceeded, parameter-problem } accept |
57 | 42 |
|
58 | | - # Handle IPv4 traffic. |
59 | | - table ip filter { |
60 | | - chain input { |
61 | | - type filter hook input priority 0; |
62 | | - # Handle existing connections. |
63 | | - ct state invalid reject |
64 | | - ct state {established, related} accept |
65 | | - # Allow loopback for applications. |
66 | | - iifname lo accept |
67 | | - # Allow people to ping us on LAN. |
68 | | - ip protocol icmp ip daddr $LAN accept |
69 | | - # Allow SSH over LAN. |
70 | | - tcp dport 22 ip daddr $LAN accept |
71 | | - # Reject all other output traffic. |
72 | | - reject |
73 | | - } |
| 43 | + # allow "ping" |
| 44 | + ip6 nexthdr icmp icmpv6 type echo-request accept |
| 45 | + ip protocol icmp icmp type echo-request accept |
74 | 46 |
|
75 | | - chain output { |
76 | | - type filter hook output priority 0; |
77 | | - # Handle existing connections. |
78 | | - ct state invalid reject |
79 | | - ct state {established, related} accept |
80 | | - # Allow loopback for applications. |
81 | | - oifname lo accept |
82 | | - # Allow the Tor user to run its daemon, |
83 | | - # but only on WAN in case of compromise. |
84 | | - skuid tor ip daddr != $LAN accept |
85 | | - # Allowing pinging others on LAN. |
86 | | - ip protocol icmp ip daddr $LAN accept |
87 | | - # Reject all other output traffic. |
88 | | - reject |
89 | | - } |
| 47 | + # accept SSH connections (required for a server) |
| 48 | + tcp dport 22 accept |
90 | 49 |
|
91 | | - chain forward { |
92 | | - type filter hook forward priority 0; |
93 | | - reject |
94 | | - } |
| 50 | + # count and drop any other traffic |
| 51 | + counter drop |
95 | 52 | } |
96 | 53 |
|
97 | | - # Block all IPv6 traffic. |
98 | | - table ip6 filter { |
99 | | - chain input { |
100 | | - type filter hook input priority 0; |
101 | | - reject |
102 | | - } |
103 | | -
|
104 | | - chain output { |
105 | | - type filter hook output priority 0; |
106 | | - reject |
107 | | - } |
| 54 | + # Allow all outgoing connections. |
| 55 | + chain output { |
| 56 | + type filter hook output priority 0; |
| 57 | + accept |
| 58 | + } |
108 | 59 |
|
109 | | - chain forward { |
110 | | - type filter hook forward priority 0; |
111 | | - reject |
112 | | - } |
| 60 | + chain forward { |
| 61 | + type filter hook forward priority 0; |
| 62 | + accept |
113 | 63 | } |
114 | | - ''; |
| 64 | + } |
| 65 | + ''; |
115 | 66 | description = |
116 | 67 | '' |
117 | 68 | The ruleset to be used with nftables. Should be in a format that |
|
0 commit comments