Skip to content

Commit 6c36d9f

Browse files
committed
nftables: make default configuration null
reason: - We currently have an open discussion regarding a more modular firewall (#23181) and leaving null makes future extension easier. - the current default might not cover all use cases (different ssh port) and might break setups, if applied blindly
1 parent ec47fac commit 6c36d9f

1 file changed

Lines changed: 32 additions & 81 deletions

File tree

nixos/modules/services/networking/nftables.nix

Lines changed: 32 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,97 +21,48 @@ in
2121
};
2222
networking.nftables.ruleset = mkOption {
2323
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;
3631
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
4534
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
5537
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
5742
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
7446
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
9049
91-
chain forward {
92-
type filter hook forward priority 0;
93-
reject
94-
}
50+
# count and drop any other traffic
51+
counter drop
9552
}
9653
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+
}
10859
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
11363
}
114-
'';
64+
}
65+
'';
11566
description =
11667
''
11768
The ruleset to be used with nftables. Should be in a format that

0 commit comments

Comments
 (0)