-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnft.2nic.router.sh
executable file
·218 lines (136 loc) · 4.23 KB
/
nft.2nic.router.sh
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
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/nft -f
#
# last modified 2017.06.04
#
set -o nounset
set -o errexit
#set -o noclobber
set -o noglob
define world = ens3
define lan = ens4
# nics:
#
# ens3 = world
# ens4 = lan
flush ruleset
table ip filter {
chain input {
type filter hook input priority 0; policy drop;
# invalid connections
ct state invalid drop
# loopback interface
iifname lo accept
# established/related connections
ct state {established, related} accept
# incoming inet trafic
iifname $world ip protocol tcp goto my_world_tcpv4
iifname $world ip protocol udp goto my_world_udpv4
iifname $world ip protocol icmp goto my_world_icmpv4
iifname $lan ip protocol tcp goto my_lan_tcpv4
iifname $lan ip protocol udp goto my_lan_udpv4
iifname $lan ip protocol icmp goto my_lan_icmpv4
}
chain my_world_tcpv4 {
# invalid connections
#ct state invalid drop
# loopback interface
#iifname lo accept
# established/related connections
#ct state {established, related} accept
# bad tcp -> avoid network scanning:
#tcp flags & (fin|syn) == (fin|syn) drop
#tcp flags & (syn|rst) == (syn|rst) drop
#tcp flags & (fin|syn|rst|psh|ack|urg) == 0 drop
#tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop
# open tcp ports: ssh
tcp dport ssh counter accept
tcp dport ssh ct state new tcp flags & (syn | ack) == syn counter accept
}
chain my_world_udpv4 {
# invalid connections
#ct state invalid drop
# loopback interface
#iifname lo accept
# established/related connections
#ct state {established, related} accept
}
chain my_world_icmpv4 {
# invalid connections
#ct state invalid drop
# loopback interface
#iifname lo accept
# established/related connections
#ct state {established, related} accept
icmp type { echo-request, echo-reply, destination-unreachable, parameter-problem } counter accept
limit rate 10/second counter accept
}
chain my_lan_tcpv4 {
# invalid connections
#ct state invalid drop
# loopback interface
#iifname lo accept
# established/related connections
#ct state {established, related} accept
# bad tcp -> avoid network scanning:
#tcp flags & (fin|syn) == (fin|syn) drop
#tcp flags & (syn|rst) == (syn|rst) drop
#tcp flags & (fin|syn|rst|psh|ack|urg) == 0 drop
#tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop
# open tcp ports: ssh,dns,dhcp
tcp dport { 22,53,67,68 } accept
}
chain my_lan_udpv4 {
# invalid connections
#ct state invalid drop
# loopback interface
#iif lo accept
# established/related connections
#ct state {established, related} accept
# open tcp ports: dns,dhcp
#iifname $lan tcp dport { 67,68 } accept
tcp dport { 67,68 } accept
}
chain my_lan_icmpv4 {
# invalid connections
#ct state invalid drop
# loopback interface
#iif lo accept
# established/related connections
#ct state {established, related} accept
iifname $lan icmp type { echo-request, echo-reply, destination-unreachable, parameter-problem } counter accept
iifname $lan limit rate 10/second counter accept
accept
}
chain output {
type filter hook output priority 0; policy drop;
# invalid connections
ct state invalid drop
# loopback interface
oif lo accept
}
chain forward {
type filter hook forward priority 0; policy drop;
# invalid connections
ct state invalid drop
# loopback interface
iifname lo accept
# established/related connections
ct state {established, related} accept
iifname $world oifname $lan ct state {established, related} accept
iifname $lan oifname $world ct state {established, related} accept
#iifname $lan oifname $world tcp dport { 22,53,80,443 } counter accept
#iifname $lan oifname $world udp dport { 53 } counter accept
}
}
table nat {
chain prerouting {
type nat hook prerouting priority -150;
}
chain postrouting {
type nat hook postrouting priority -150; policy accept;
oifname $world masquerade
# snat
#ip saddr 192.168.199.0/24 oifname $world snat 192.168.199.108
}
}