-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfox_firewall_nftables.conf
208 lines (160 loc) · 7.95 KB
/
fox_firewall_nftables.conf
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/sbin/nft -f
# This configuration file is customized by fox,
# Optimize nftables rules for Linux Router.
table inet router
flush table inet router
table inet router {
#
# NFTsets
#
set local_dns_ipv4 {
type ipv4_addr;
elements = { 172.16.1.2, 172.16.1.3 };
}
set local_dns_ipv6 {
type ipv6_addr;
elements = { ::0000:00ff:fe00:0001, ::0000:00ff:fe00:0002 };
}
#
# Flowtable
#
flowtable ft {
hook ingress priority filter;
devices = { enp6s18, enp6s19, enp6s20, enp6s21 };
counter;
}
#
# Filter rules
#
chain input {
type filter hook input priority filter; policy drop;
ct state established,related accept comment "defconf: handle inbound flows"
iif "lo" accept comment "defconf: accept traffic from loopback"
ct state new meta l4proto tcp jump syn_flood comment "defconf: rate limit new TCP connections"
iifname "bridge1" jump input_lan comment "defconf: handle LAN IPv4 / IPv6 input traffic"
iifname { "pppoe1", "enp6s18" } jump input_wan comment "defconf: handle WAN IPv4 / IPv6 input traffic"
}
chain forward {
type filter hook forward priority filter; policy drop;
ct state established,related goto handle_offload comment "defconf: handle forwarded flows"
iifname "bridge1" jump forward_lan comment "defconf: handle LAN IPv4 / IPv6 forward traffic"
iifname { "pppoe1", "enp6s18" } jump forward_wan comment "defconf: handle WAN IPv4 / IPv6 forward traffic"
}
chain output {
type filter hook output priority filter; policy accept;
ct state vmap { established : accept, related : accept, invalid : drop } comment "defconf: handle outbound flows"
oif "lo" accept comment "defconf: accept traffic towards loopback"
oifname "bridge1" jump output_lan comment "defconf: handle LAN IPv4 / IPv6 output traffic"
oifname { "pppoe1", "enp6s18" } jump output_wan comment "defconf: handle WAN IPv4 / IPv6 output traffic"
}
chain prerouting {
type filter hook prerouting priority filter; policy accept;
ct state invalid counter drop comment "defconf: drop packets in invalid flow state"
iifname "bridge1" jump helper_lan comment "defconf: handle LAN IPv4 / IPv6 helper assignment"
}
chain syn_flood {
limit rate 200/second burst 100 packets return comment "defconf: accept new TCP connections below rate-limit"
counter drop comment "defconf: drop excess new TCP connections"
}
chain handle_offload {
flow add @ft comment "defconf: track forwarded flows"
accept
}
chain input_lan {
ct status dnat accept comment "lanconf: accept port redirect"
jump accept_from_lan
}
chain forward_lan {
jump accept_to_wan comment "defconf: accept LAN to WAN forwarding"
ct status dnat accept comment "lanconf: accept port forwards"
jump accept_to_lan
}
chain output_lan {
jump accept_to_lan
}
chain helper_lan {
}
chain accept_from_lan {
iifname "bridge1" accept comment "defconf: accept LAN IPv4 / IPv6 traffic"
}
chain accept_to_lan {
oifname "bridge1" accept comment "defconf: accept LAN IPv4 / IPv6 traffic"
}
chain input_wan {
meta nfproto ipv4 udp dport 68 counter accept comment "defconf: allow DHCP renew"
meta nfproto ipv4 icmp type echo-request counter drop comment "defconf: drop ICMP-Ping input"
meta nfproto ipv4 meta l4proto igmp counter accept comment "defconf: allow IGMP"
ip6 daddr fe80::/10 udp dport 546 counter accept comment "defconf: allow DHCPv6"
ip6 saddr fe80::/10 icmpv6 type . icmpv6 code { mld-listener-query . no-route, mld-listener-report . no-route, mld-listener-done . no-route, mld2-listener-report . no-route } counter accept comment "defconf: allow MLD"
meta nfproto ipv6 icmpv6 type echo-request counter drop comment "defconf: drop ICMPv6-Ping input"
meta nfproto ipv6 icmpv6 type { destination-unreachable, time-exceeded, echo-reply, nd-router-solicit, nd-router-advert } limit rate 200/second burst 100 packets counter accept comment "defconf: allow ICMPv6 input"
meta nfproto ipv6 icmpv6 type . icmpv6 code { packet-too-big . no-route, parameter-problem . no-route, nd-neighbor-solicit . no-route, nd-neighbor-advert . no-route, parameter-problem . admin-prohibited } limit rate 200/second burst 100 packets counter accept comment "defconf: allow ICMPv6 input"
jump drop_from_wan
}
chain forward_wan {
meta nfproto ipv6 icmpv6 type { destination-unreachable, time-exceeded, echo-request, echo-reply } limit rate 200/second burst 100 packets counter accept comment "defconf: allow ICMPv6 forward"
meta nfproto ipv6 icmpv6 type . icmpv6 code { packet-too-big . no-route, parameter-problem . no-route, parameter-problem . admin-prohibited } limit rate 200/second burst 100 packets counter accept comment "defconf: allow ICMPv6 forward"
jump drop_to_wan
}
chain output_wan {
jump accept_to_wan
}
chain accept_to_wan {
oifname { "pppoe1", "enp6s18" } accept comment "defconf: accept WAN IPv4 / IPv6 traffic"
}
chain drop_from_wan {
iifname { "pppoe1", "enp6s18" } counter drop comment "defconf: drop WAN IPv4 / IPv6 traffic"
}
chain drop_to_wan {
oifname { "pppoe1", "enp6s18" } counter drop comment "defconf: drop WAN IPv4 / IPv6 traffic"
}
#
# NAT rules
#
chain dstnat {
type nat hook prerouting priority dstnat; policy accept;
iifname "bridge1" meta l4proto { tcp, udp } th dport domain jump dstnat_lan comment "defconf: handle LAN IPv4 / IPv6 dstnat traffic"
}
chain srcnat {
type nat hook postrouting priority srcnat; policy accept;
oifname { "pppoe1", "enp6s18" } jump srcnat_wan comment "defconf: handle WAN IPv4 / IPv6 srcnat traffic"
}
chain dstnat_lan {
ip saddr @local_dns_ipv4 meta l4proto { tcp, udp } th dport domain counter accept comment "lanconf: accept LAN IPv4 DNS bootstrap query"
ip6 saddr & ::ffff:ffff:ffff:ffff == @local_dns_ipv6 meta l4proto { tcp, udp } th dport domain counter accept comment "lanconf: accept LAN IPv6 DNS bootstrap query"
meta nfproto ipv4 meta l4proto { tcp, udp } th dport domain counter redirect to domain comment "lanconf: LAN IPv4 DNS redirect"
meta nfproto ipv6 meta l4proto { tcp, udp } th dport domain counter redirect to domain comment "lanconf: LAN IPv6 DNS redirect"
}
chain srcnat_wan {
meta nfproto ipv4 masquerade comment "defconf: masquerade WAN IPv4 traffic"
}
#
# Raw rules (notrack)
#
chain raw_prerouting {
type filter hook prerouting priority raw; policy accept;
}
chain raw_output {
type filter hook output priority raw; policy accept;
}
#
# Mangle rules
#
chain mangle_prerouting {
type filter hook prerouting priority mangle; policy accept;
}
chain mangle_postrouting {
type filter hook postrouting priority mangle; policy accept;
ct packets < 20 oifname { "pppoe1", "enp6s18" } tcp flags syn / fin,syn,rst tcp option maxseg size set rt mtu comment "defconf: zone WAN IPv4 / IPv6 egress MTU fixing"
}
chain mangle_input {
type filter hook input priority mangle; policy accept;
}
chain mangle_output {
type route hook output priority mangle; policy accept;
}
chain mangle_forward {
type filter hook forward priority mangle; policy accept;
ct packets < 20 iifname { "pppoe1", "enp6s18" } tcp flags syn / fin,syn,rst tcp option maxseg size set rt mtu comment "defconf: zone WAN IPv4 / IPv6 ingress MTU fixing"
}
}